nginx同一端口实现不同域名对应不同静态页,并转发

代码配置详情nginx.conf

`  server {
    listen       80;
    server_name  ad.bjhxsm.net;
    #charset koi8-r;
    #access_log  logs/host.access.log  main;
    location /page {
        root  /usr/local;
        index  index.html index.htm;
    }   
    location / {
         proxy_pass   http://127.0.0.1:8081;
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header REMOTE-HOST $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }    
}


server {
    listen       80;
    server_name  ad.cnqywin.com;
    #charset koi8-r;
    #access_log  logs/host.access.log  main;
    location /page {
        root  /usr/local;
        index  index.html index.htm;
    }   
    location / {
         proxy_pass   http://127.0.0.1:8081;
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header REMOTE-HOST $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }    
}
 `   
    原文作者:养码哥
    原文地址: https://www.jianshu.com/p/c798dac9b2ed
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞