找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 63|回复: 5

咨询下nginx大佬

[复制链接]

20

主题

69

回帖

260

积分

中级会员

积分
260
发表于 2017-11-14 15:37:26 | 显示全部楼层 |阅读模式
网站更换域名,如何把网站所有地址重定向到对应新地址?
比如 old.com/1.html -> new.com/1.html
old.com/a/4.html -> new.com/a/4.html
回复

使用道具 举报

7

主题

137

回帖

317

积分

中级会员

积分
317
发表于 2017-11-14 16:10:33 | 显示全部楼层
本帖最后由 jk13 于 2017-11-14 16:13 编辑

server {

     server_name  old.com;
        
    return 301 https://new.com$request_uri; # 如果新网站没有使用 https  那就将 https 修改成 http

        
   }

不需要 写 listen
Nginx 默认 监听 80
回复

使用道具 举报

303

主题

2745

回帖

6481

积分

论坛元老

积分
6481
发表于 2017-11-14 16:00:18 | 显示全部楼层
可以用反代实现吧。

[ol]
  • server
  • {
  •     listen 80;
  •     server_name new.com www.new.com;
  •     location /
  •     {
  •         proxy_pass http://old.com;
  •         proxy_set_header Host old.com;
  •         proxy_set_header X-Forwarded-For $remote_addr;
  •         proxy_cache_key old.com$request_uri$is_args$args;
  •         proxy_cache_valid 200 304 301 302 1h;
  •         add_header X-Cache $upstream_cache_status;
  •         proxy_set_header Accept-Encoding "";
  •         sub_filter "old.com" "new.com";
  •         sub_filter_once off;
  •         expires 12h;
  •     }
  •    
  •     location ~ .*\.(php|jsp|cgi|asp|aspx|flv|swf|xml)?$
  •     {
  •         proxy_set_header Host old.com;
  •         proxy_set_header X-Forwarded-For $remote_addr;
  •         proxy_pass http://old.com;
  •         proxy_set_header Accept-Encoding "";
  •         sub_filter "old.com" "new.com";
  •         sub_filter_once off;
  •     }
  •     access_log  /root/new.com.log;
  • }
  • [/ol]复制代码
  • 回复

    使用道具 举报

    49

    主题

    413

    回帖

    1057

    积分

    金牌会员

    积分
    1057
    发表于 2017-11-14 15:43:39 | 显示全部楼层
    location / {
    rewrite (.*) http://new.com$request_uri;
    }
    回复

    使用道具 举报

    20

    主题

    69

    回帖

    260

    积分

    中级会员

    积分
    260
     楼主| 发表于 2017-11-14 16:05:00 | 显示全部楼层

    chinni 发表于 2017-11-14 15:43

    location / {
    rewrite (.*) http://new.com$request_uri;
    }

    设置了,但是如http://old.com/about.php这种还是无法跳转呢
    回复

    使用道具 举报

    28

    主题

    579

    回帖

    1312

    积分

    金牌会员

    积分
    1312
    发表于 2017-11-14 16:05:58 | 显示全部楼层
    301跳转好用,谢谢各位大佬~~
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    Archiver|手机版|小黑屋|Discuz! X

    GMT+8, 2025-5-10 13:27 , Processed in 0.020416 second(s), 4 queries , Gzip On, Redis On.

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表