Configure Nginx for virtual hosts with same port

guruprasads nginx-forum at forum.nginx.org
Tue Jun 20 10:17:27 UTC 2017


Hi all,

I am trying to configure 3 virtual hosts for single server with same port,
but php is not working for all virtual hosts.

My requirement is as below,

IP:port-A/
IP:port-A/local 
IP:port-A/viewer

These 3 virtual hosts i want to configure, only html contents are displaying
on browser, if i add php code its not displaying any php actions(like i
written simply echo "guru";).

below is my configuration file content.

server {

listen       80 default;
        listen       443 ssl;
        server_name  $hostname;
        client_max_body_size 16384M;

location / {
                root /opt/xxx/yyy/myweb/admin;
                index  index.php index.phtml index.html index.htm;
                try_files $uri $uri/ /index.php$is_args$args;
         }

location /viewer {
                root /opt/xxx/yyy/myweb/viewer;
                index  index.php index.phtml index.html index.htm;
                try_files $uri $uri/ /index.php$is_args$args;
         }

location /local {
                root /opt/xxx/yyy/myweb/local;
                index  index.php index.phtml index.html index.htm;
                try_files $uri $uri/ /index.php$is_args$args;
         }


location ~ \.php$ {
                root /opt/xxx/yyy/myweb/admin;
                try_files $uri =404;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_intercept_errors on;
                fastcgi_read_timeout 300;
                include fastcgi_params;
        }

location ~ \.php$ {
                root  /opt/xxx/yyy/myweb/viewer;
                try_files $uri =404;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_intercept_errors on;
                fastcgi_read_timeout 300;
                include fastcgi_params;
        }

location ~ \.php$ {
                root  /opt/xxx/yyy/myweb/local;
                try_files $uri =404;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_intercept_errors on;
                fastcgi_read_timeout 300;
                include fastcgi_params;
        }
}

advance thanks all.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,274978,274978#msg-274978



More information about the nginx mailing list