› NGINX
› NGINX Trac
› 3rd Party Modules
› Security Advisories
› CHANGES
› OpenResty
› ngx_lua
› Tengine
在线学习资源
› NGINX 开发从入门到精通
NGINX Modules
› ngx_echo
70599
V2EX  ›  NGINX

nginx 怎样把 www.example.com 重定向到 example.com 上?

  •  
  •   70599 · Nov 23, 2015 · 3707 views
    This topic created in 4011 days ago, the information mentioned may be changed or developed.
    4 replies  •  2015-11-24 12:25:14 +08:00
    msg7086
    msg7086
    Nov 23, 2015
    1
    server_name www.example.com;
    rewrite ^ http://example.com;
    UtopiaCHN
    UtopiaCHN
    Nov 23, 2015
    2
    应该在域名解析上设置吧,最开始不是只有 http://example.com 吗,我是自己加的 www.example.com
    imkh
    imkh
    Nov 24, 2015❤️3
    3
    server {
    listen 80;
    server_name www.old-name.com;
    return 301 $scheme://www.new-name.com$request_uri;
    }

    官方推荐用法

    https://www.nginx.com/blog/creating-nginx-rewrite-rules/#gs.BtHsKaw
    ychongsaytc
    ychongsaytc
    Nov 24, 2015
    4
    3 楼正解。
    条件跳转不是个好办法。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2536 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 00:34 · PVG 08:34 · LAX 16:34 · JFK 19:34
    ♥ Do have faith in what you're doing.