Welcome! Log In Create A New Profile

Advanced

two virtual hosts with same domain name but different ports?

Posted by nginx_chen 
two virtual hosts with same domain name but different ports?
August 03, 2018 08:52AM
Hi,

I have a virtual host running fine, say:

sample.com
server {
listen 80;
server_name sample.com;
...




now I need to set up another virtual host but same name, say:

sample.com:3000

I put the new conf file:
server {
listen 3000;
server_name sample.com;
...


but http://sample.com:3000 always goes back to sample.com, any idea how to make it work? Thanks

Chen
Re: two virtual hosts with same domain name but different ports?
August 07, 2018 09:35PM
Hi,

I am done with my following configuration and it works,
make sure your firewall allows those ports

server {
listen 80;
location / {

proxy_pass "http://IP_AppServer:80";
proxy_set_header X-proxy IP_Nginx;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_next_upstream error timeout invalid_header http_500 http_404;
proxy_set_header X-Client-IP $remote_addr;
}
}
server {
listen 8080;
location / {

proxy_pass "http://IP_AppServer:8080";
proxy_set_header X-proxy IP_Nginx;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_next_upstream error timeout invalid_header http_500 http_404;
proxy_set_header X-Client-IP $remote_addr;
}
}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 62
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready