简体   繁体   English

nginx:[警告] 0.0.0.0:80 上的服务器名称“域”冲突,忽略

[英]nginx: [warn] conflicting server name "domain" on 0.0.0.0:80, ignored

I've bought a domain name, deployed my django application to DigitalOcean, but this error doesn't let me use application.我已经购买了一个域名,将我的 django 应用程序部署到 DigitalOcean,但是这个错误并没有让我使用应用程序。 How can I ignore this error ?我怎样才能忽略这个错误? Here are my codes:这是我的代码:

setting.py:设置.py:

ALLOWED_HOSTS = ['blablabla.com', '64.225.12.157']

nginx: nginx:

server {
    listen 80;
    server_name blablabla.com;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/sammy/myproject;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/sammy/myproject/myproject.sock;
    }
}

default nginx:默认 Nginx:

        root /var/www/blablabla.com;

        index index.html index.htm index.nginx-debian.html;

        server_name blablabla.com;

        location / {
                try_files $uri $uri/ =404;
        }

You have two issues (the second one is mostly a recommendation):您有两个问题(第二个主要是建议):


First:第一的:

You've defined the server_name directive in two places -- one in the default http block and one in a server block.您已经在两处定义了server_name指令——一处在默认的http块中,另一处在server块中。 Drop the reference in the default http block and keep only the one at the server block.删除默认http块中的引用,只保留server块中的引用。 Also unless you know what you're doing, drop the location / directive from http block as well, the locations are usually put in the server block to do URL mappings for that server.此外,除非您知道自己在做什么,否则也要从http块中删除location /指令,这些位置通常放在server块中,以便为该服务器进行 URL 映射。 Putting that in http block does the mapping globally, which causes a headache while tracking the mapping down while debugging.将它放在http块中进行全局映射,这会导致在调试时跟踪映射时头疼。


Second:第二:

Django talks the WSGI protocol, so (in production) a WSGI server is needed to send request and get response back from Django. Django 使用 WSGI 协议,因此(在生产中)需要一个 WSGI 服务器来发送请求并从 Django 获取响应。 Presumably, you're using one given by the reference to the UNIX domain socket:据推测,您正在使用由对 UNIX 域套接字的引用给出的一个:

/home/sammy/myproject/myproject.sock

So if your WSGI server (eg uWSGI , gunicorn ) listens on that socket for incoming requests, and also send the response via that, you need to tell Nginx to use WSGI protocol to send-retrieve data from the socket and also pass relevant WSGI parameters.因此,如果您的 WSGI 服务器(例如uWSGIgunicorn )在该套接字上侦听传入请求,并通过该套接字发送响应,则需要告诉 Nginx 使用 WSGI 协议从套接字发送-检索数据并传递相关的 WSGI 参数. An example of this would be:这方面的一个例子是:

upstream foobar {
    server unix:///home/sammy/myproject/myproject.sock;
}

server {
    server_name blablabla.com;
    ...
    ...
    location / {
        uwsgi_pass foobar;
        include /etc/nginx/uwsgi_params;
    }
}

Your current configuration with reverse proxying via proxy_pass will work but using WSGI gets you closer to the underlying protocol used by underlying layers hence is recommended.您当前通过proxy_pass使用反向代理的配置将起作用,但使用 WSGI 可以让您更接近底层使用的底层协议,因此建议使用。

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

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