1

Why nginx run default page ? how to listen my django server ?

First inside the sites-availabe folder i created example.com file then i

[root@instance-4 sites-available]# ls -al /etc/nginx/sites-enabled/example.com 
lrwxrwxrwx. 1 root root 21 Dec 22 11:03 /etc/nginx/sites-enabled/example.com -> example.com

/etc/nginx/sites-available/example.com

server {
        listen 80;
        server_name example.com;

        location / {
            proxy_pass http://127.0.0.1:8000;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

Then when i run gunicorn example.wsgi in my app folder and later i visited the example.com but you know what i am still getting nginx default page.

What i am missing here ?

Updated :

Now this time i created example.com file in my Django root folder then after Symlink

[root@instance-4 Staging]# ln -s example.com /etc/nginx/sites-enabled/

after the nginx restart still same ...

Updated 2 :

nginx.conf file

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    include /etc/nginx/sites-enabled/*;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
5
  • Your ls seems strange. sites-enabled/example.com seems to be linked to itself, and not to sites-available/example.com. Commented Dec 22, 2014 at 11:24
  • @DanielRoseman those are 2 dirs , available and enabled Commented Dec 22, 2014 at 11:34
  • Did you forget to reload the server? Commented Dec 22, 2014 at 11:38
  • @DRC yes two but @Daniel is correct see this configure-nginx-for-your-site. I got confused which one i follow ... Commented Dec 22, 2014 at 11:40
  • @BurhanKhalid after the nginx restart i run gunicorn example.wsgi ... Commented Dec 22, 2014 at 11:41

2 Answers 2

1

Check for a default in /etc/nginx/site-enabled/ and remove it if it's there. Then reload or restart your nginx server.

You can also check gunicorn is serving requests by visiting example.com:8000.

It's worthwhile noting that you'll probably also want nginx to be serving your static files so put in a /static/ block:

location /static/ {
    alias /path/to/your/app/static/;
    if ($query_string) {
        # If using GET params to control versions, set to max expiry.
        expires max;
    }
    access_log off;
}
Sign up to request clarification or add additional context in comments.

6 Comments

See gunicorn is running( 127.0.0.1:8000 ) And in my above configuration means i can able to see the html content of my django in example.com .. right ? but i am seeing only nginx default page ..
no actually i'm setting this up on google cloud computing So port 8000 i can't access ...
ah okay - just a suggestion. Make sure you've removed that default and and check the sites-enabled folder is being included in your /etc/nginx/nginx.conf (there should be a line: include /etc/nginx/sites-enabled/*;)
by default nginx sites-enabled folder is not there . i only create that.. is that ok ?
see there is no tutorial there .. see this page they mentioning sites-available only but i am using sites-enabled what should i follow ..
|
0

From what i remember of nginx, there is 2 places where you can find the index.html of nginx, try to do a "find / -name index.html" you will prolly find the 2nd .html i am talking about, and regarding the path u should be able to fix this

1 Comment

Please include more detail in your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.