简体   繁体   中英

How to listen nginx port 80 to django server?

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;
}

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;
}

根据我对nginx的记忆,有2个地方可以找到nginx的index.html,尝试做一个“ find / -name index.html”,您会找到我正在谈论的第二个.html,并且关于你应该能够解决这个问题的路径

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM