1

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!

trynacode
  • 361
  • 1
  • 8
  • 18
  • Did you try replacing `html` in `location / { root html; ... ` with a path to the directory where your `index.html` file is present (for example: `/home/user/Documents/MyProject`)? – Ajeet Shah Jun 22 '16 at 18:59
  • Yes, so that I did is I went to my index.html file in the directory and ran pwd on it and replaced the old path with this pwd value. Basically it looks like `location / { root /home/parallels/Desktop/MyProject/nginx/html;` – trynacode Jun 22 '16 at 19:03
  • Also I don't know if this is to be edited but there is a file named nginx.conf.default that looks just like nginx.conf. The only difference is that everytime I build/make nginx, this nginx.conf.default goes back to its default values ( so even if I change the path, if I want to make the new binary file and build nginx, my changes go away). Do you think I should be spending more time focusing on this nginx.conf.default file and making changes there? – trynacode Jun 22 '16 at 19:06
  • I think, you should configure `Nginx.conf` file, not the `Nginx.conf.default`. – Ajeet Shah Jun 22 '16 at 19:08
  • Okay, that is what I was thinking. Yeah unfortunately I have to clone a repo online and utilize that, and that repo is Nginx 1.8. I looked at the link that you referred, but it looks like none of the suggestions from the correct answer applies since none of them are issues for me. Thanks for the link though! – trynacode Jun 22 '16 at 19:14

1 Answers1

1

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.

Ajeet Shah
  • 18,551
  • 8
  • 57
  • 87
  • Hmm, see I have something similar in that my index.html is in the path that I gave next to `root`. If it matters, I am using an absolute path, not a relative path. Could the `server_name` make a difference? Mines just states localhost, which I am not too sure what it indicates. – trynacode Jun 22 '16 at 19:22
  • Yeah there is a `127.0.0.1 localhost`. I'm just so confused as to why this error is showing...it must be something really dumb but I can't find it. – trynacode Jun 22 '16 at 19:35
  • I'm just using one html file right now. I had to build FAST CGI with nginx but right now I'm having trouble correctly running nginx so haven't looked at the FAST CGI part yet. – trynacode Jun 22 '16 at 20:05
  • I tried copying pasting from your "You should check if this works for you:" but it still results in the same 404 Not Found. Could this be anything related to PHP? That seems to be a common thing when researching this problem but I'm using index.html, a html file, so didn't feel like it was too applicable. – trynacode Jun 22 '16 at 23:41
  • Doesn't appear that there is an error.log anywhere in my directory. – trynacode Jun 23 '16 at 03:31
  • One last attempt to solve this before I ask for further help, but is there a way I can check to see whether nginx actually is using the information in nginx.conf when it's running? I changed the `listen` value to `8000` instead, but when I tried running my `ipaddress:8000` it resulted in a page could not be loaded error whereas a `ipaddress:80` still resulted in the same 404 not found. I assumed that nginx is calling on nginx.conf values when running (hopefully that assumption isn't wrong) but it seems like changing the values of nginx.conf has no effect on nginx. – trynacode Jun 23 '16 at 16:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/115433/discussion-between-orions-and-trynacode). – Ajeet Shah Jun 23 '16 at 17:19
  • 1
    Check NginX to see what configs it's using. Stop NginX first `nginx -s stop` then run `nginx -T > nginxT-showConfigs.txt` and then open that txt file in a text editor like `nano nginxT-showConfigs.txt` to see each file it reads, and the content of each file, in the order they are read. NOTE: -t tests the nginx.conf, but -T (capitol) outputs the configs, then tests nginx.conf. – Able Mac Jul 03 '19 at 19:42