I am brand new to nginx and have it running on a VM (mynginx.example.com
) and successfully serving back some static content. So far so good.
However, it appears to be configured so that you need to specify both the port and the file you wish toview. This is mainly a problem on the homepage (index.html
) because I'd like users to be able to just go to http://mynginx.example.com
and see my homepage.
So if I open a browser and go to http://mynginx.example.com:8080/index.html
, my homepage (and all other static content) loads up just fine. But, when accessing the homepage, if I omit either the port or index.html
, the browser chokes and nginx seems to refuse to serve back anything. Meaning, the following two HTTP requests do not work:
http://mynginx.example.com:8080
<-- nopehttp://mynginx.example.com/index.html
<-- nope
Below is the nginx.conf
that I'm using:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
server {
listen 80;
server_name mynginx.example.com;
location / {
root /opt/mysite;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
Can anybody figure out what I need to do in order to make http://mynginx.example.com
the same as http://mynginx.example.com:8080/index.html
(from nginx's perspective)? Meaning, I'd like the users to be able to just use the main domain name and have nginx serve back index.html
(which is located at /opt/mysite/index.html
).
Update
I changed 8080
to 80
and that fixed the port issue. However, now (with port 80
specified), going to both http://mynginx.example.com
and http://mynginx.example.com/index.html
have the exact same effect: they take you to the default nginx page (Welcome to nginx!)...
So by changing the port from 8080 -> 80 now some nginx default is kicking in and is preventing me from getting to my index.html
page.
I did have HTTP GET errors in the error log but I fixed them and they were separate from the behavior I'm seeing here. The logs (access and error) are now empty.
listen
directive.http://mynginx.example.com/index.html
? What is the purpose ofroot html;
in thelocation = /50x.html
block? In generalroot
directive should be in theserver
level, not inside alocation
.server_name
If this is your only site try commenting out your 3include
lines as this will remove any other configurations from the question