简体   繁体   中英

Cannot load a php page with nginx - 502 Bad gateway

I have PHP 7.2.17 and Nginx 1.15.9 on Ubuntu 19.04. I have this nginx configuration :

server {  
  listen 80;
  listen [::]:80;
  server_name dev.frameworkcms.com;

  set $rootpath "/var/www/html/perso/framework-cms test";  

  error_log "/var/www/html/perso/framework-cms test/logs/error.log" error;
  # combined by default
  access_log "/var/www/html/perso/framework-cms test/logs/access.log";

  root $rootpath/web;

  location ~ \.php$ {
    fastcgi_intercept_errors on;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_index Resources.php;
    #fastcgi_pass 127.0.0.1:9000;
    fastcgi_pass unix:/var/run/php7.2-fpm.sock;
  }
}

I tried with the port 9000 as well. i can see the index.html at the project root but not the file web/Resources.php .

I always have a 502 Bad Gateway . Logs are empty.

Edit

I just added a line try_files \\$uri /Resources.php; at the beginning of the location block. Now the php file is offered for download...

Edit

Thanks to @Pete Cooper, I have found that the .sock file is not the good one.

Here is the new version of the file :

server {  
  listen 80;
  listen [::]:80;
  server_name dev.frameworkcms.com;

  set $rootpath "/var/www/html/perso/framework-cms test";  

  error_log "/var/www/html/perso/framework-cms test/logs/error.log" error;
  # combined by default
  access_log "/var/www/html/perso/framework-cms test/logs/access.log";

  root $rootpath/web;

  location ~ \.php$ {
    try_files \$uri /Resources.php;
    fastcgi_intercept_errors on;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_index Resources.php;
    #fastcgi_pass 127.0.0.1:9000;
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
  }
}

I now have a 500 Internal Server Error. I precise that I work locally.

尝试重新启动php-fpm服务。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM