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

请教一个 nginx 配置问题,关于 rewrite 的写法

  •  
  •   ghy459 ·
    ghy459 · 2015-12-08 22:59:05 +08:00 · 2775 次点击
    这是一个创建于 3062 天前的主题,其中的信息可能已经有所发展或是发生改变。
    折腾了一晚上 nginx ,发现一个 nginx 配置需求实现不了
    1 、 http://www.xxx.com/blog/.* 正常请求 /wwwdata/xxx/blog 下的一个 wordpress
    2 、 http://www.xxx.com/ 302 到 http://www.xxx.com/blog/
    3 、其余请求 http://www.xxx.com/.* 都 302 到另外一个 URL http://www.aaa.com/

    目前的配置是

    server
    {
    listen 80;
    server_name www.xxx.com;
    index index.php;
    root /wwwdata/xxx;

    location = /
    {
    rewrite . http://www.xxx.com/blog/ redirect;
    }

    location ~ [^/]\.php(/|$)
    {
    try_files $uri =404;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    include fastcgi_params;
    fastcgi_index index.php;
    }
    }

    第一和第二两点都好操作,但当我尝试加入 location ^~ / 貌似所有请求都进去这个 location 了, php 也不解析。
    nginx 自学的也没太懂,请问各位大牛这个该咋写?
    3 条回复    2015-12-09 08:42:28 +08:00
    ryd994
        1
    ryd994  
       2015-12-09 00:10:28 +08:00 via Android
    location / {
    return http://www.aaa.com/
    }
    没事用什么 regex
    location = / 也不需要 rewrite 。直接 return http://www.xxx.com/blog/就行
    还有,今后例子还是 a.com b.com 比较好。我手贱点开了链接,周围人的眼神都不对了
    shyling
        2
    shyling  
       2015-12-09 02:30:42 +08:00 via iPad
    如楼上。。第三个用默认的 location /{}就行了。。 return 302 http://xxx.com;
    lhbc
        3
    lhbc  
       2015-12-09 08:42:28 +08:00 via Android
    location 匹配有优先级,合理利用优先级就行了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1271 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 18:08 · PVG 02:08 · LAX 11:08 · JFK 14:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.