I am Trying to create two instance on my NGnix server
First would be accessed by
mydomain.com (it listening to port 80 )
Second using
172.32.32.123:81 (it listening to port 81 and this IP is server IP)
this is my default file
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name mydomain.com;
location / {
try_files $uri $uri/ =404;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
}
location ~ /.ht {
deny all;
}
}
server {
listen 81;
server_name 172.32.32.123:81;
root /var/www/html/root;
index index.html index.php;
set $MAGE_MODE developer; # or production or developer
set $MAGE_ROOT /var/www/html/root/;
location / {
try_files $uri $uri/ =404;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
}
include /var/www/html/root/nginx.conf.sample;
}
}
The server block is working fine for the one when using domain name but in case of IP based domain only home page is working on inner pages we are getting 404 error
3
Answers
Solved the issue with using following default config
Inclusion of try_files Solved the issue for me
It’s unclear what’s supposed to happen — what is the correct path that’s supposed to handle one server versus the other?!
If they’re supposed to have the same underlying files, then your
root
directives are quite suspicious — one is simply/var/www/html/
, the other one is/var/www/html/root/
— is that intentional?Otherwise, in case of a 404 error, the underlying path names (that aren’t found) should be mentioned within the file specified by http://nginx.org/r/error_log, which will likely reveal what is up — do those returning 404 actually exist on the disc?!
This would be better moved to ServerFault.
While I’m not sure of it, The inclusion of the port in the ServerName directive looks suspicious to me.
This looks dangerous:
include /var/www/html/root/nginx.conf.sample
If /var/www/html/root, and the directories above it are only writeable by root, it might be OK. Otherwise it’s likely to be a root exploit for whichever user can write to the file. Copy the file to somewhere safe, and include it at that location.