context
I have 2 Linux Red Hat machines hosting nginx server. Nginx server is working with below config:
nginx config server 1
user1@server1:/etc/nginx/conf.d $ cat docgen_react.conf
server{
listen 80;
listen [::]:80;
server_name url1.com;
root /home/user1/gru/documentgenerator/react_client/build;
index index.html index.htm;
}
nginx config server 2
user2@server2:/etc/nginx/conf.d $ cat docgen_react.conf
server{
listen 80;
listen [::]:80;
server_name url2.com;
root /export/home/user2/gru/documentgenerator/react_client/build;
index index.html index.htm;
}
current behavior
expected behavior
To sum-up if I use IP address I want to reach the same page as if I am navigating via www.url2.com
Thanks to @ThanhNguyenVan's comment, I found the solution.
I was only focusing on /etc/nginx/conf.d and as I am not familiar with nginx I was not aware that there was a config above i.e /etc/nginx/nginx.conf. I then compare the server1 vs server2 config and saw the difference.
After commenting that part below it worked like charm:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}