nginx管理本地服务器取决于收入域名 [英] nginx manage local servers depends on income domain name

查看:146
本文介绍了nginx管理本地服务器取决于收入域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个在defferents端口上运行localy的应用程序,如何配置NGINX服务器,以便从80端口到我的应用程序的转发请求取决于收入域名。例如,端口8181上的两个本地应用程序名为'app1',如果请求来自 http://app1.com - nginx转发到 http: // localhost:8181



我看过nginx文档,请问有人做了这个例子。
谢谢

解决方案

假设您要创建一个反向代理,我的方法是首先在一个名为 /etc/nginx/reverse-proxy.conf的新文件中配置以下反向代理设置

 #服务于本地http服务器。 
#只需将以下内容添加到各个vhost配置中:
#proxy_pass http:// localhost:3001 /;

proxy_pass_header服务器;
proxy_set_header主机$ http_host;
proxy_redirect关闭;
proxy_set_header X-Real-IP $ remote_addr;
proxy_set_header X-Scheme $ scheme;
proxy_connect_timeout 10;
proxy_read_timeout 10;

然后,对于正在配置的每个反向代理,我添加了一个适当命名的配置文件, code> / 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 /;
}
}

您可以创建多个服务器块,并将其指向不同的本地(甚至远程)应用程序服务器。您还可以添加位置块,以静态或不同的本地应用程序服务器在同一个域内提供不同的URL。



/etc/nginx/nginx.conf 中,但是我觉得更容易将配置分离成多个文件。)


I have a few applications that are running localy in defferents ports, how can I configure NGINX server for forwarding request from port 80 to my application depends on income domain name. For example 2 local apps named 'app1' on port 8181 , and if request comes from http://app1.com - nginx forwards to http://localhost:8181

I've looked at nginx docs, I ask for your examples if someone did this. Thanks

解决方案

Assuming you want to create a reverse proxy, my method is to first configure the following reverse proxy settings in a new file called /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;

Then, for each reverse proxy I'm configuring, I add an appropriately-named configuration file in /var/nginx/sites-enabled with the following:

server {
    server_name app1.com;
    server_name www.app1.com;
    location / {
        include /etc/nginx/reverse-proxy.conf;
        proxy_pass http://localhost:8181/;
    }
}

You can create as many server blocks as you like and point them at different local (or even remote) application servers. You can also add location blocks to serve different URLs within the same domain statically, or from different local application servers.

(You can also just roll all the configuration into /etc/nginx/nginx.conf, but I find it easier to separate configuration out into multiple files.)

这篇关于nginx管理本地服务器取决于收入域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆