【发布时间】:2017-06-20 05:39:04
【问题描述】:
我在一个 ubuntu 16 服务器上有两个网站,我希望使用 nginx reverse proxy 和 gunicorn 让它们通过网络访问(Gunicorn 在内部为 127.0.0.1:8000 和 127.0.0.1:8001 上的网站提供服务。
两个网站永远不会让DNS指向我的服务器,并且两个必须在端口80下运行。所以问题是,如何为这些站点设置反向代理?我处于无法捕获主机名或其他端口以便用户进入特定站点的情况。
我的 first_website.conf:
upstream first_website {
server unix:/var/www/first_website/first_website_env/run/gunicorn.sock
fail_timeout=0;
}
server {
listen 80;
# normally I would use different host name
# to check, which site user wants to retrieve.
server_name 123.12.34.789;
client_max_body_size 4G;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
proxy_pass http://127.0.0.1:8001;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://127.0.0.1:8001;
break;
}
}
}
【问题讨论】:
-
那么您打算如何区分服务器?你想让他们有不同的进入点吗?例如
123.12.34.789/server1? -
是的 123.12.34.789/server1 将是一个不错的选择。但我不确定如何实现这一点,以及这是否是一个好习惯。
标签: nginx reverse-proxy gunicorn