2017-01-28 134 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;