Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
883 views
in Technique[技术] by (71.8m points)

dns - nginx manage local servers depends on income domain name

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 /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/;
    }
}

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.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...