2017-01-28 159 views
2

我在Ubuntu 16.04服務器nginxphp7.0-fpmLaravel 5.4應用程序設置nginx的和php7.0-FPM,它給502錯誤網關Laravel 5.4在Ubuntu

502 Bad Gateway 

的Nginx虛擬主機配置,

server { 
    listen 80; ## listen for ipv4; this line is default and implied 
    #listen [::]:80 default ipv6only=on; ## listen for ipv6 

    root /var/www/html/laravel/public; 
    index index.php index.html; 

    # Make site accessible from http://localhost/ 
    server_name localhost; 

    location/{ 
     try_files $uri $uri/ /index.php?$query_string; 
    } 

    location ~ \.php$ { 
     try_files $uri /index.php =404; 
     include     fastcgi_params; 
     fastcgi_keep_conn on; 
     fastcgi_index   index.php; 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_param PATH_INFO $fastcgi_path_info; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_intercept_errors on; 
     fastcgi_pass unix:/var/run/php7.0-fpm.sock; 
    } 
} 

試過以下,但仍然沒有工作,

改變fastcgi_pass unix:/var/run/php7.0-fpm.sock;fastcgi_pass 127.0.0.1:9000;

改變try_files $uri $uri/ /index.php?$query_string;try_files $uri $uri/ /index.php$is_args$args;

重啓動服務的每個變化後,

service nginx restart 
service php7.0-fpm restart 

我可以用這個配置只能訪問的主要途徑,

server { 
     listen 80; ## listen for ipv4; this line is default and implied 
     #listen [::]:80 default ipv6only=on; ## listen for ipv6 

     root /var/www/html/laravel/public; 
     index index.html index.htm index.php; 

     # Make site accessible from http://localhost/ 
     server_name localhost; 

     location/{ 
       try_files $uri $uri/ =404; 
     } 

     location ~ \.php$ { 
       include snippets/fastcgi-php.conf; 
       fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
     } 

     location ~ /\.ht { 
       deny all; 
     } 
} 

回答

2

更新與默認的PHP一行基於配置工作,

server { 
     listen 80; ## listen for ipv4; this line is default and implied 
     #listen [::]:80 default ipv6only=on; ## listen for ipv6 

     root /var/www/html/laravel/public; 
     index index.html index.htm index.php; 

     # Make site accessible from http://localhost/ 
     server_name localhost; 

     location/{ 
       try_files $uri $uri/ /index.php?$query_string; 
     } 

     location ~ \.php$ { 
       include snippets/fastcgi-php.conf; 
       fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
     } 

     location ~ /\.ht { 
       deny all; 
     } 
} 

這裏改變了try_files $uri $uri/ =404;try_files $uri $uri/ /index.php?$query_string;