Skip to content


nginx反向代理多个域名(虚似主机)

nginx反向代理同一ip多个域名,给header加上host就可以了

proxy_set_header Host $host;

nginx.conf例子

upstream mysvr {
server 127.0.0.1:8080;
}
server
{
listen 80;
server_name servera.c1gstudio.com;
index index.html index.htm index.php;
root /opt/htdocs/www;

location / {
proxy_pass http://mysvr;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server
{
listen 80;
server_name serverb.c1gstudio.com;
index index.html index.htm index.php;
root /opt/htdocs/www;

location / {
proxy_pass http://mysvr;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

Posted in Nginx, 技术.

Tagged with , .


5 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. an9 says

    学习一下。

  2. yzhkpli says

    俩域名指向同一个网站了?

  3. C1G says

    说的是一IP多域名,是不是同一网站看你后端

  4. apinglai says

    请问用nginx 的blog主机头,反向代理apache 83端口下的虚拟目录 wordpress如何配置呢

  5. C1G says

    proxy_pass http://192.168.0.10:83/wordpress;
    可以试试,未经验证



Some HTML is OK

or, reply to this post via trackback.