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

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

问题描述

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

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

我查看了 nginx 文档,如果有人这样做,我会询问您的示例.谢谢

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

推荐答案

假设你想创建一个 reverseproxy,我的方法是先在一个名为/etc/nginx/reverse-proxy.conf的新文件中配置如下反向代理设置:

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;

然后,对于我配置的每个反向代理,我在 /etc/nginx/sites-enabled 中添加一个适当命名的配置文件,内容如下:

Then, for each reverse proxy I'm configuring, I add an appropriately-named configuration file in /etc/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/;
    }
}

您可以根据需要创建任意数量的 server 块,并将它们指向不同的本地(甚至远程)应用程序服务器.您还可以添加 location 块以静态地为同一域内的不同 URL 或来自不同本地应用程序服务器的 URL 提供服务.

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.

(您也可以将所有配置滚动到 /etc/nginx/nginx.conf,但我发现将配置分离到多个文件中更容易.)

(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天全站免登陆