当前位置:网站首页>Openresty redirection
Openresty redirection
2022-07-04 14:48:00 【o_ Guatian Lixia_ o】
openresty Redirect
Redirect
Redirect : Avoid website paths 、 After the domain name is changed , The original link of the website is invalid
Command format :rewrite old_url new_url [flag]
old_url: old url route , It can be a regular expression
new_url: New jump url, After matching the regular expression , Jump to this address
# flag: Identification of further processing
last: End rewrite, The server jumps to the specified path
break: End rewrite, No more matching
redirect: Temporary redirection , Return response code 302
permanent: Permanent redirection , Return response code 301
Example
default.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/local/openresty/nginx/html;
index index.html index.htm;
}
#location 1
location /break {
root /usr/share/nginx/html2;
if ( !-e $request_filename ){ #root Find files in the directory /default/info
rewrite ^/break/(.*) /default/info break;
}
}
#location 2
location /break2 {
root /usr/share/nginx/html2;
if ( !-e $request_filename ){ #root Find files in the directory /default/info,
# Then continue to execute the following statement ,echo "break"
rewrite ^/break2/(.*) /default/info break;
echo "break";
}
}
#location 3
location /last {
if ( !-e $request_filename ){ # After the match , Jump to /test/$1 route
rewrite ^/last/(.*) /test/$1 last;
echo "last";
}
}
#location 4
location /test {
echo "test";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/openresty/nginx/html;
}
}
Local files
[email protected] redirect % pwd
/Users/huli/lua/openresty/redirect
[email protected] redirect % ls html
default
[email protected] redirect % ls html/default
info
[email protected] redirect % cat html/default/info
break info
Create a container
docker run -it -d -p 1000:80 \
-v /Users/huli/lua/openresty/redirect/html:/usr/local/openresty/nginx/html2 \
-v /Users/huli/lua/openresty/redirect/default.conf:/etc/nginx/conf.d/default.conf \
--name open2 lihu12344/openresty
Use tests
[email protected] redirect % curl localhost:1000/break/1
break info
[email protected] redirect % curl localhost:1000/break2/1
break
[email protected] redirect % curl localhost:1000/last
last
[email protected] redirect % curl localhost:1000/last/1
test
[email protected] redirect % curl localhost:1000/test
test
Example 2
default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /redirect {
if ( !-e $request_filename ) {
rewrite ^/redirect/(.*) /test/$1 redirect;
}
}
location /permanent {
if ( !-e $request_filename ) {
rewrite ^/permanent/(.*) /test/$1 permanent;
}
}
location /test {
echo "test";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Create a container
docker run -it -d -p 2000:80 \
-v /Users/huli/lua/openresty/redirect/default2.conf:/etc/nginx/conf.d/default.conf \
--name open3 lihu12344/openresty
Use tests
[email protected] redirect % curl -I localhost:2000/redirect/1
HTTP/1.1 302 Moved Temporarily
Server: openresty/1.21.4.1
Date: Mon, 04 Jul 2022 04:50:08 GMT
Content-Type: text/html
Content-Length: 151
Location: http://localhost/test/1
Connection: keep-alive
[email protected] redirect % curl -I localhost:2000/permanent/1
HTTP/1.1 301 Moved Permanently
Server: openresty/1.21.4.1
Date: Mon, 04 Jul 2022 04:50:17 GMT
Content-Type: text/html
Content-Length: 175
Location: http://localhost/test/1
Connection: keep-alive
边栏推荐
- Yyds dry goods inventory # solve the real problem of famous enterprises: continuous maximum sum
- C language achievement management system for middle school students
- Nowcoder reverse linked list
- 关于FPGA底层资源的细节问题
- [MySQL from introduction to proficiency] [advanced chapter] (IV) MySQL permission management and control
- Combined with case: the usage of the lowest API (processfunction) in Flink framework
- IO流:节点流和处理流详细归纳。
- MySQL stored procedure exercise
- LVGL 8.2 Draw label with gradient color
- Leetcode t49: grouping of alphabetic words
猜你喜欢
leetcode:6110. 网格图中递增路径的数目【dfs + cache】
LVGL 8.2 text shadow
5G电视难成竞争优势,视频资源成中国广电最后武器
Nowcoder rearrange linked list
Detailed explanation of visual studio debugging methods
A keepalived high availability accident made me learn it again
leecode学习笔记-约瑟夫问题
03-存储系统
函数计算异步任务能力介绍 - 任务触发去重
Gin integrated Alipay payment
随机推荐
Detailed analysis of pytorch's automatic derivation mechanism, pytorch's core magic
Comment configurer un accord
[cloud native] how can I compete with this database?
IO流:节点流和处理流详细归纳。
LVGL 8.2 Draw label with gradient color
Solutions aux problèmes d'utilisation de l'au ou du povo 2 dans le riz rouge k20pro MIUI 12.5
Count the running time of PHP program and set the maximum running time of PHP
LVGL 8.2 Line
LVGL 8.2 Line
EventBridge 在 SaaS 企业集成领域的探索与实践
LVGL 8.2 Menu
openresty 重定向
Graduation season - personal summary
Yyds dry goods inventory # solve the real problem of famous enterprises: continuous maximum sum
函数计算异步任务能力介绍 - 任务触发去重
LVGL 8.2 text shadow
SqlServer函数,存储过程的创建和使用
LVGL 8.2 LED
SAIC Maxus officially released its new brand "mifa", and its flagship product mifa 9 was officially unveiled!
【算法leetcode】面试题 04.03. 特定深度节点链表(多语言实现)