This is a creation in Article, where the information may have evolved or changed.
Existing two Golang Web service programs: web1 (8080), WEB2 (8081), two domain names:www.xxxxx.com, www.yyyy.com
On one machine, the xxxxx.com resolves to port 8080 and yyyy.com resolves to 8081 ports
Ways to reverse proxy using Nginx:
First, in the Nginx configuration file, add the following configuration
server{
Listen 80;
server_name www.xxxxx.com xxxxx.com;
Location/{
Try_files/_not_exists @backend;
}
Location @backend {
Proxy_set_header x-forwarded-for $remote _addr;
Proxy_set_header Host $http _host;
Proxy_pass http://localhost:8080;
}
}
Domain xxxxx.com,www.xxxxx.com can be resolved to server 8080 port
server{
Listen 80;
server_name www.yyyy.com yyyy.com;
Location/{
Try_files/_not_exists @backend;
}
Location @backend {
Proxy_set_header x-forwarded-for $remote _addr;
Proxy_set_header Host $http _host;
Proxy_pass http://localhost:8081;
}
}
Domain yyyy.com,www.yyyy.com can be resolved to server 8081 port.