我有几个应用程序正在运行本地端口,我怎样才能配置NGINX服务器转发请求从端口80到我的应用程序取决于收入域名。例如,在端口8181上名为'app1'的2个本地应用程序,如果请求来自于http://app1.com
- nginx转发到http://localhost:8181
nginx管理本地服务器取决于收入的域名
我看过nginx文档,我问你的例子,如果有人这样做。 感谢
我有几个应用程序正在运行本地端口,我怎样才能配置NGINX服务器转发请求从端口80到我的应用程序取决于收入域名。例如,在端口8181上名为'app1'的2个本地应用程序,如果请求来自于http://app1.com
- nginx转发到http://localhost:8181
nginx管理本地服务器取决于收入的域名
我看过nginx文档,我问你的例子,如果有人这样做。 感谢
假设你想创建一个reverse proxy,我的方法是在一个名为/etc/nginx/reverse-proxy.conf
新文件首先配置以下反向代理服务器设置:
# Serve/from local http server.
# Just add the following to individual vhost configs:
# proxy_pass http://localhost:3001/;
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;
然后,对于每个反向代理我配置,我在/var/nginx/sites-enabled
添加一个合适的名字命名的配置文件有以下几点:
server {
server_name app1.com;
server_name www.app1.com;
location/{
include /etc/nginx/reverse-proxy.conf;
proxy_pass http://localhost:8181/;
}
}
,你喜欢,你可以创建许多server
块和迪菲指出他们租用本地(甚至远程)应用程序服务器。您还可以添加location
块来静态地或在不同的本地应用程序服务器上为同一个域内的不同URL提供服务。
(你也可以只推出所有的配置到/etc/nginx/nginx.conf
,但我觉得它更容易配置分离成多个文件。)
我设法通过以下this tutorial做到这一点很容易。
创建/etc/nginx/conf.d/
称为your-domain.com.conf
一个新的文件,并把这个在它:
server {
listen 80;
server_name your-domain.conf.com;
location/{
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368;
}
}
然后重启nginx的
sudo service nginx restart
感谢。这很有帮助。 – 2015-03-17 15:08:53
不是/ var/nginx,而是/ etc/nginx。 – Timopheym 2017-10-10 09:54:34