bas*_*sh- 44 ubuntu nginx gunicorn
这是我的第一个 Web 应用程序部署,并且遇到了各种问题。
我目前正在为 Django 应用程序寻找 nginx + gunicorn 实现,但这个问题主要与 nginx 配置有关。对于某些情况 - nginx 将接收到 gunicorn 本地服务器的连接和代理。
在 nginx 配置中,它说server_name我必须提供一个吗?我不打算使用任何类型的域名,只是通过我网络的外部 ip(它是静态的)和要监听的端口号。
我的愿望是当我访问类似的东西时,http://xxx.xxx.xxx.xxx:9050我将能够获得该网站。
以下是我将基于配置的示例代码以供参考。
server {
listen 80;
server_name WHAT TO PUT HERE?;
root /path/to/test/hello;
location /media/ {
# if asset versioning is used
if ($query_string) {
expires max;
}
}
location /admin/media/ {
# this changes depending on your python version
root /path/to/test/lib/python2.6/site-packages/django/contrib;
}
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 10;
proxy_read_timeout 10;
proxy_pass http://localhost:8000/;
}
# what to serve if upstream is not available or crashes
error_page 500 502 503 504 /media/50x.html;
}
Run Code Online (Sandbox Code Playgroud)
Sha*_*den 38
server_name默认为空字符串,这很好;你可以完全排除它。
“我不想为此命名”需要的另一种常见方法是使用 server_name _;
但是,您的http://xxx.xxx.xxx.xxx:9050URL 不适用于此配置;你只监听端口 80。你还需要添加一个listen 9050;。
服务器名称 _; 不是通配符,请参见此处:
http://blog.gahooa.com/2013/08/21/nginx-how-to-specify-a-default-server
只需为 ip-only 访问指定 default_server 指令(请参阅http://nginx.org/en/docs/http/request_processing.html)
server {
listen 1.2.3.4:80 default_server;
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
133844 次 |
| 最近记录: |