北大青鸟小游网:值得大家信赖的游戏下载站!

微信:96kaifa
关注我们
所在位置:首页 > 服务器 > 使用nginx怎么重定向地址(图文)

使用nginx怎么重定向地址(图文)

发布时间:2021-06-24 09:58:45来源:北大青鸟手游网作者:北大青鸟手游网

in
in
  • 游戏类别:社交聊天
  • 游戏大小:
  • 游戏语言:
  • 游戏版本:
点击查看
扫码查看

这期内容当中小编将会给大家带来有关使用nginx怎么重定向地址,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

1、假设要把webroot/static/index.html访问重定向到static/index.html

例如当我们通过浏览器访问http://192.168.11.210/webroot/static/index.html,实际访问的是web目录下面的static/index.html文件,也及去掉了webroot这个目录,使用alias

location ^~ /webroot/ {
 alias /data/www/web/WebContent/;
}

注意:

1. 使用alias时,目录名后面一定要加"/"。

2. alias可以指定任何名称。

3. alias在使用正则匹配时,必须捕捉要匹配的内容并在指定的内容处使用。

4. alias只能位于location块中。[/warning]

http://192.168.11.210/webroot/test/static/index.html

location ^~ /webroot/test/ {
 alias /data/www/web/WebContent/;
}

这样也是可以的,最终访问的文件跟上面是一样的。

2、把对webroot/static/index.html的访问重定向到web目录下面的test目录下

location ~ ^/webroot/ {
 root /data/www/web/WebContent/test/;
}

http://192.168.11.210/webroot/static/index.html 实际访问的是web目录下testwebroot/static/index.html
及使用root一般是把访问目录重定向到某个目录下,但是访问的路径必须在重新定位的目录下

注意区分跟alias的区别

转载一个:

访问域名 

www.adc.com/image  自动跳转到  www.adc.com/make/image 

这个如何写

这种需求有多种方法可以实现:

1. 利用Nginx rewrite 内部跳转实现:

location /image {
     rewrite ^/image/(.*)$   /make/image/$1 last;
}

2.利用alias映射

location /image {
    alias /make/image; #这里写绝对路径}

3.利用root映射:

location /image {
   root  /make;
}

4.利用nginx的permanent 301绝对跳转实现

location /image {
    rewrite ^/image/(.*)$  http://www.adc.com/make/image/$1;
}

5.判断uri实现

if ( $request_uri ~* ^(/image)){
    rewrite ^/image/(.*)$ /make/image/$1 last; 
}

上述就是小编为大家分享的使用nginx怎么重定向地址了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。


我要评价

  • 热门资讯
  • 最新资讯
  • 手游排行榜
  • 手游新品榜