V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
buobuk
V2EX  ›  NGINX

nginx反代两个不同域名,域名的IP不一样. 我这样配置对吗?

  •  
  •   buobuk · 2013-07-13 17:00:30 +08:00 · 3288 次点击
    这是一个创建于 3941 天前的主题,其中的信息可能已经有所发展或是发生改变。
    upstream

    myhost1 {
    server 192.168.1.1:80 weight=1 max_fails=2 fail_timeout=30s;
    }

    myhost2 {
    server 192.168.1.2:80 weight=1 max_fails=2 fail_timeout=30s;
    }

    #####

    server {
    listen 80;
    server_name www.xxx.com;
    location /
    {
    proxy_pass http://myhost1;
    proxy_cache_key $host$uri$is_args$args;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_cache_valid 200 304 12h;
    expires 2d;
    }

    location ~ /purge(/.*)
    {
    allow 127.0.0.1;
    deny all;
    proxy_cache_purge cache_one $host$1$is_args$args;
    }

    location ~ .*\.(php|jsp|cgi|asp|aspx|flv|swf|xml)?$
    {
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_pass http://myhost1;
    }
    access_log off;
    }

    server {
    listen 80;
    server_name www.yyy.com;
    location /
    {
    proxy_pass http://myhost2;
    proxy_cache_key $host$uri$is_args$args;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_cache_valid 200 304 12h;
    expires 2d;
    }

    location ~ /purge(/.*)
    {
    allow 127.0.0.1;
    deny all;
    proxy_cache_purge cache_one $host$1$is_args$args;
    }

    location ~ .*\.(php|jsp|cgi|asp|aspx|flv|swf|xml)?$
    {
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_pass http://myhost2;
    }
    access_log off;
    }
    4 条回复    1970-01-01 08:00:00 +08:00
    Livid
        1
    Livid  
    MOD
       2013-07-13 17:01:32 +08:00   ❤️ 1
    这样写没问题。
    Livid
        2
    Livid  
    MOD
       2013-07-13 17:02:03 +08:00
    不过似乎 myhost2 前面少了 upstream?
    buobuk
        3
    buobuk  
    OP
       2013-07-13 17:02:21 +08:00
    @Livid 谢谢
    buobuk
        4
    buobuk  
    OP
       2013-07-13 17:03:38 +08:00
    @Livid 嗯,我的就是想问一下,myhost2是不是要upstream
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2791 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 10:08 · PVG 18:08 · LAX 03:08 · JFK 06:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.