首页 > 网站 > 建站经验 > 正文

ngin配置301重定向设置方法和nginx子目录301重定向

2019-11-02 15:55:59
字体:
来源:转载
供稿:网友

nginx版本为1.1.19。

若域名由a.com转移到了b.com,并对两个域名有所有权,可以:

复制代码 代码如下:

server{

    server_name a.com;

    return 301 $scheme://b.com$request_uri;

}

重启服务器,然后看一下成功与否:

复制代码 代码如下:

curl -I a.com

nginx子目录301重定向设置方法

如我想把www.b.com/bfiles/download/转向到dx1.b.com:81/bfiles/download/下,nginx下网站的conf文件里这些写:

复制代码 代码如下:

location ~* ^/bfiles/download/ { 

rewrite ^/bfiles/download/(.*)$ http://dx1.b.com:81/bfiles/download/$1 permanent; 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表