• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

Issue Nginx not handling index.php, passed to Apache instead

OlgaKM

Basic Pleskian
I have set the settings on my server to run PHP 7.0 via nginx + php-fpm. When I access a script by name, e.g. "http://www.somedomain.com/index.php", this works correctly. However, if I access "http://www.somedomain.com/", the script is executed, but handled not by nginx + php-fpm, but by Apache. I can tell because the script is a simple phpinfo() script: when nginx handles it, the PHP version is listed as 7.0, while when Apache does it, it's listed as 5.4, which is the default PHP version on my system (OS vendor does not support anything higher).

I do not have any custom nginx or Apache directives set up on this domain. Any tips on resolving this issue?

nginx_ip_default.conf (all other nginx* .conf files are empty):

Code:
#ATTENTION!
#
#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,
#SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.

server {
        listen 443;
        server_name somedomain.com;
        return 301 https://www.somedomain.com$request_uri;
}

server {
        listen XXX.XXX.XXX.XXX:443 default_server ssl;

        server_name www.somedomain.com;
        server_name ipv4.somedomain.com;

        ssl_certificate             /usr/local/psa/var/certificates/cert-XCt0Ft;
        ssl_certificate_key         /usr/local/psa/var/certificates/cert-XCt0Ft;

        client_max_body_size 128m;

        proxy_read_timeout 600;

        root "/var/www/vhosts/somedomain.com/httpdocs";
        access_log "/var/www/vhosts/system/somedomain.com/logs/proxy_access_ssl_log";
        error_log "/var/www/vhosts/system/somedomain.com/logs/proxy_error_log";

        location ^~ /plesk-site-preview/ {
                proxy_pass http://127.0.0.1:8880;
                proxy_set_header Host             plesk-site-preview.local;
                proxy_set_header X-Real-IP        $remote_addr;
                proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
                access_log off;
        }

        location / {
                proxy_pass https://XXX.XXX.XXX.XXX:7081;
                proxy_set_header Host             $host;
                proxy_set_header X-Real-IP        $remote_addr;
                proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
                proxy_set_header X-Accel-Internal /internal-nginx-static-location;
                access_log off;
        }

        location /internal-nginx-static-location/ {
                alias /var/www/vhosts/somedomain.com/httpdocs/;
                add_header X-Powered-By YNginx;
                internal;
        }

        index index.html index.cgi index.pl index.php index.xhtml index.htm index.shtml;

        location ~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon) {
                proxy_pass https://XXX.XXX.XXX.XXX:7081;
                proxy_set_header Host             $host;
                proxy_set_header X-Real-IP        $remote_addr;
                proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
                proxy_set_header X-Accel-Internal /internal-nginx-static-location;
                access_log off;
        }

        location ~ ^/~(.+?)(/.*?\.php)(/.*)?$ {
                alias /var/www/vhosts/somedomain.com/web_users/$1/$2;
                fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_pass "unix:///var/www/vhosts/system/somedomain.com/php-fpm.sock";
                include /etc/nginx/fastcgi.conf;
        }

        location ~ ^/~(.+?)(/.*)?$ {
                proxy_pass https://XXX.XXX.XXX.XXX:7081;
                proxy_set_header Host             $host;
                proxy_set_header X-Real-IP        $remote_addr;
                proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
                proxy_set_header X-Accel-Internal /internal-nginx-static-location;
                access_log off;
        }

        location ~ \.php(/.*)?$ {
                fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_pass "unix:///var/www/vhosts/system/somedomain.com/php-fpm.sock";
                include /etc/nginx/fastcgi.conf;
        }

        include "/var/www/vhosts/system/somedomain.com/conf/vhost_nginx.conf";

}

server {
        server_name somedomain.com;
        return 301 http://www.somedomain.com$request_uri;
}

server {
        listen XXX.XXX.XXX.XXX:80 default_server;

        server_name www.somedomain.com;
        server_name ipv4.somedomain.com;

        client_max_body_size 128m;

        proxy_read_timeout 600;

        root "/var/www/vhosts/somedomain.com/httpdocs";
        access_log "/var/www/vhosts/system/somedomain.com/logs/proxy_access_log";
        error_log "/var/www/vhosts/system/somedomain.com/logs/proxy_error_log";

        location ^~ /plesk-site-preview/ {
                proxy_pass http://127.0.0.1:8880;
                proxy_set_header Host             plesk-site-preview.local;
                proxy_set_header X-Real-IP        $remote_addr;
                proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
                access_log off;
        }

        index index.php index.html index.cgi index.pl index.xhtml index.htm index.shtml;

        location / {
                proxy_pass http://XXX.XXX.XXX.XXX:7080;
                proxy_set_header Host             $host;
                proxy_set_header X-Real-IP        $remote_addr;
                proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
                proxy_set_header X-Accel-Internal /internal-nginx-static-location;
                access_log off;
        }

        location /internal-nginx-static-location/ {
                alias /var/www/vhosts/somedomain.com/httpdocs/;
                add_header X-Powered-By PleskNginx;
                internal;
        }

        location ~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon) {
                proxy_pass http://XXX.XXX.XXX.XXX:7080;
                proxy_set_header Host             $host;
                proxy_set_header X-Real-IP        $remote_addr;
                proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
                proxy_set_header X-Accel-Internal /internal-nginx-static-location;
                access_log off;
        }

        location ~ ^/~(.+?)(/.*?\.php)(/.*)?$ {
                alias /var/www/vhosts/somedomain.com/web_users/$1/$2;
                fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_pass "unix:///var/www/vhosts/system/somedomain.com/php-fpm.sock";
                include /etc/nginx/fastcgi.conf;
        }

        location ~ ^/~(.+?)(/.*)?$ {
                proxy_pass http://XXX.XXX.XXX.XXX:7080;
                proxy_set_header Host             $host;
                proxy_set_header X-Real-IP        $remote_addr;
                proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
                proxy_set_header X-Accel-Internal /internal-nginx-static-location;
                access_log off;
        }

        location ~ \.php(/.*)?$ {
                fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_pass "unix:///var/www/vhosts/system/somedomain.com/php-fpm.sock";
                include /etc/nginx/fastcgi.conf;
        }

        include "/var/www/vhosts/system/somedomain.com/conf/vhost_nginx.conf";

}
 
Last edited:
It looks as if you have still enabled "Proxy mode" in the "nginx" section of the "Apache & Nginx Settings" of the domain, because in your configuration file the proxy sections are still present. If proxy mode is enabled, all file requests that are not in the "static" file extension list will be proxied to httpd. For that reason the .php extension can be identified as PHP, but an "empty" extension (for the index page) will not be identified to be handled by the PHP module for Nginx. Please try to disable proxy mode, restart Nginx afterwards to have it read the new configuration (or wait until the restart interval expires) and test again.

Edit: Oops, sorry, I made a mistake. You have posted this in the 12.x section. The setting I have considered is not available in Plesk 12.x, it is only available in 17.x or younger. I'll need to think about this again then. It's probably the correct reason given, but you need a different solution, because in 12.x you cannot do Nginx-only hosting.
 
I *do* have a checkbox for "Serve static files directly by nginx" in the Apache & nginx settings page. Is this what you're referring to?

Also, might a block like the following work?

Code:
location @proxy {
               proxy_pass http://XXX.XXX.XXX.XXX:7080;
               proxy_set_header Host             $host;
               proxy_set_header X-Real-IP        $remote_addr;
               proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
               proxy_set_header X-Accel-Internal /internal-nginx-static-location;
               access_log off;
}

location ~ /$ {
               try_files $uri/index.php @proxy;
}
 
Back
Top