我在一个ubuntu 16
服务器上有两个网站,我想通过网络使用nginx
reverse proxy
和gunicorn
访问这些网站(Gunicorn内部为{{}}提供网站服务1}}和127.0.0.1:8000
)。
两个网站都从不让127.0.0.1:8001
指向我的服务器,必须在端口DNS
下运行。所以问题是,如何为这些网站设置反向代理?我处于无法捕获主机名或不同端口以便用户进入特定站点的情况。
我的first_website.conf:
80
答案 0 :(得分:0)
一个选项是将服务器放在不同的URL位置,例如:
upstream first_website {
server unix:/var/www/first_website/first_website_env/run/gunicorn.sock
fail_timeout=0;
}
server {
listen 80;
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 /server1/ {
proxy_pass http://127.0.0.1:8000;
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:8000;
break;
}
}
location /server2/ {
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;
}
}
}
我相信这对你来说很有用。