trynacode
trynacode

Reputation: 371

404 Not Found when using Nginx Web Server

I have been getting a 404 Not Found with nginx/1.8.0 in the bottom of the screen when running my IP ADDRESS on a browser. I know that this is a frequently asked question, as I've seen multiple posts on this issue, and I have spent the past 4-5 hours looking through those posts but for some reason have still not been able to fix this issue. So right now I know that the nginx.conf file must be edited in order to reflect the right path of the HTML file. This is how my nginx.conf file looked like on default:

worker_processes  2;

pid        logs/nginx.pid;
error_log syslog:server=unix:/dev/log,facility=local7,tag=nginx,severity=error;

events {
worker_connections  1024;
}


http {
include       mime.types;
default_type  application/octet-stream;

access_log syslog:server=unix:/dev/log,facility=local7,tag=nginx,severity=info combined;

sendfile        on;
keepalive_timeout  65;


server {
    listen       80;
    server_name  localhost;

    location / {
     root   html;

    index  index.html index.htm;
        autoindex on;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}
}

So after looking at the .conf file, I realized that the root /path/ might be causing the issue. So what I did is I went to my index.html file in the directory and ran pwd on it and replaced the path with this pwd value. I then proceeded to build/make nginx again and I restarted nginx as well. However, this is still resulting in a 404 Not Found error, so I am unsure whether I am misinterpreting the meaning of root or if there is some other issue. I also am aware that there may be some issue from switching over form Apache to Nginx, and that this may result in a 404 Not Found error if not properly handled though I couldn't get much information and how to check whether this is truly applicable to my situation or not. Can anyone point me towards the right direction as to how I can fix this issue? I have been compiling Nginx on Ubuntu through sourcing (not by calling sudo apt-get install) as this is what I was instructed to do. I know that Nginx is running, since when I tell it to stop there is a "Unable to connect: Firefox can't establish a connection to the server at ...", I'm just stuck on this weird issue.

Please let me know if inadequate information was provided, and if so, what information I should add to make the post more clear! Thank you!

Upvotes: 1

Views: 13660

Answers (1)

Ajeet Shah
Ajeet Shah

Reputation: 19813

Make sure your nginx.conf file looks somewhat as shown below:

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   /home/user_name/Documents/your_proj; # You need to provide here the path of your "index.html" file
            index  index.html index.htm;
        }
}

You must have an index.html or index.htm file under your directory /home/user_name/Documents/your_proj as shown in above configuration.

Upvotes: 1

Related Questions