Nginx根據不一樣域名轉發到本地不一樣端口服務

server {
    listen       80;
    server_name  ops.liyuchang.com; #監聽ops.liyuchang.com域名
    #charset koi8-r;
    #access_log  logs/host.access.log  main;
    #proxy_read_timeout 60;
    #proxy_ignore_client_abort on;
    
    location / {
        proxy_pass http://localhost:9528; #轉到本地9528服務
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}
server {
    listen       80;
    server_name  m.liyuchang.com; #監聽m.liyuchang.com域名
    #charset koi8-r;
    #access_log  logs/host.access.log  main;
    #proxy_read_timeout 60;
    #proxy_ignore_client_abort on;
    
    location / {
        proxy_pass http://localhost:8080; #轉到本地8080服務
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

localhost默認轉下第一個配置的服務。html

相關文章
相關標籤/搜索