簡體   English   中英

部署Laravel到Azure時宕機

[英]Downtime when deploying Laravel to Azure

我正在將 laravel 站點部署到 Azure Web 應用程序(運行 linux)。

升級到 PHP 8 和 nginx 后,我在部署后遇到了更多的停機時間。 幾分鍾的 nginx Bad Gateway 錯誤。

為了讓 laravel 與 nginx 一起工作,我需要將 nginx conf 文件從我的項目復制到服務器上的 nginx 配置中。

我在部署后運行 startup.sh,第一行有以下命令:

cp /home/site/wwwroot/devops/nginx.conf /etc/nginx/sites-available/default;
service nginx reload

我的 nginx.conf 的內容:

server {
    # adjusted nginx.conf to make Laravel 8 apps with PHP 8.0 features runnable on Azure App Service
    # @see https://laravel.com/docs/8.x/deployment
    listen 8080;
    listen [::]:8080;
    root /home/site/wwwroot/public;
    index index.php;

    client_max_body_size 100M;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    gzip on;
    gzip_proxied    any;
    gzip_min_length 256;
    gzip_types
      application/atom+xml
      application/geo+json
      application/javascript
      application/x-javascript
      application/json
      application/ld+json
      application/manifest+json
      application/rdf+xml
      application/rss+xml
      application/xhtml+xml
      application/xml
      font/eot
      font/otf
      font/ttf
      image/svg+xml
      text/css
      text/javascript
      text/plain
      text/xml;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_param HTTP_PROXY "";
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_intercept_errors on;
        fastcgi_connect_timeout         300;
        fastcgi_send_timeout           3600;
        fastcgi_read_timeout           3600;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
    }
}

我也嘗試過使用 Azure 部署槽,但交換是在 Bad Gateway 錯誤消失之前發生的。

我還能做些什么來最大程度地減少停機時間/項目重新啟動和運行的時間嗎?

“Bad Gateway”錯誤表明 Nginx 無法連接到后端,在本例中為 PHP-FPM。

您可以嘗試采取一些措施來最大程度地減少停機時間:

  • 增加 nginx 配置文件中的 fastcgi_connect_timeout、fastcgi_send_timeout 和 fastcgi_read_timeout 值。 這將使 PHP-FPM 有更多時間啟動和響應請求。

  • 優化您的 PHP 代碼。 確保您的代碼針對性能進行了優化,因為這將有助於減少網站啟動所需的時間。

  • 使用 Azure Deployment Slots 進行測試。 部署槽允許您在將代碼部署到生產環境之前在暫存環境中測試您的代碼。 這有助於降低生產環境停機的風險。

  • 嘗試確保您的 PHP-FPM 和 nginx 服務始終處於運行狀態,並且在服務器啟動時自動啟動它們。

  • 嘗試通過使用滾動升級的部署過程來減少部署期間所需的重新啟動次數。

  • 最后,您可以嘗試先部署一個簡單的 HTML 文件,然后再部署 Laravel 代碼庫。 這將確保 web 服務器和 PHP 在部署 Laravel 代碼庫之前正常工作。

通過反復試驗找出適合您的用例的最佳解決方案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM