简体   繁体   English

如何监听nginx端口80到Django服务器?

[英]How to listen nginx port 80 to django server?

Why nginx run default page ? 为什么Nginx运行默认页面? how to listen my django server ? 如何收听我的django服务器?

First inside the sites-availabe folder i created example.com file then i 首先在sites-availabe文件夹中创建了example.com文件,然后我

[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 /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. 然后,当我在我的应用程序文件夹中运行gunicorn example.wsgi并随后访问example.com ,您知道我仍然在获取nginx默认页面。

What i am missing here ? 我在这里想念什么?

Updated : 更新 :

Now this time i created example.com file in my Django root folder then after Symlink 现在这次我在Django根文件夹中创建了example.com文件,然后在Symlink之后

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

after the nginx restart still same ... 在nginx重启后还是一样的...

Updated 2 : 更新2

nginx.conf file nginx.conf文件

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. /etc/nginx/site-enabled/检查default ,如果存在则将其删除。 Then reload or restart your nginx server. 然后重新加载或重新启动您的nginx服务器。

You can also check gunicorn is serving requests by visiting example.com:8000 . 您还可以通过访问example.com:8000来检查gunicorn是否正在处理请求。

It's worthwhile noting that you'll probably also want nginx to be serving your static files so put in a /static/ block: 值得注意的是,您可能还希望nginx提供静态文件,因此将其放在/static/块中:

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,并且关于你应该能够解决这个问题的路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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