当前位置:网站首页>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
边栏推荐
- Some problems and ideas of data embedding point
- LVGL 8.2 text shadow
- 曝光一下阿里的工资待遇和职位级别
- 自动控制原理快速入门+理解
- 函数计算异步任务能力介绍 - 任务触发去重
- [algorithm leetcode] interview question 04.03 Specific depth node linked list (Multilingual Implementation)
- Ml: introduction, principle, use method and detailed introduction of classic cases of snap value
- Count the running time of PHP program and set the maximum running time of PHP
- Progress in architecture
- LVLG 8.2 circular scrolling animation of a label
猜你喜欢

软件测试之测试评估

如何配和弦

LVGL 8.2 LED

leetcode:6109. 知道秘密的人数【dp的定义】

韩国AI团队抄袭震动学界!1个导师带51个学生,还是抄袭惯犯

Stm32f1 and stm32subeide programming example -max7219 drives 8-bit 7-segment nixie tube (based on GPIO)

LVGL 8.2 text shadow

Summary of common problems in development

Free, easy-to-use, powerful lightweight note taking software evaluation: drafts, apple memo, flomo, keep, flowus, agenda, sidenote, workflow

Xcode abnormal pictures cause IPA packet size problems
随机推荐
Industrial Internet has greater development potential and more industry scenarios
Halo effect - who says that those with light on their heads are heroes
炒股网上开户安全吗?会不会被骗。
开发中常见问题总结
LeetCode 1200 最小絕對差[排序] HERODING的LeetCode之路
C language course design questions
LVGL 8.2 LED
PyTorch的自动求导机制详细解析,PyTorch的核心魔法
尊重他人的行为
Comment configurer un accord
阿里被裁员工,找工作第N天,猎头又传来噩耗...
Ali was laid off employees, looking for a job n day, headhunters came bad news
Opencv learning notes - linear filtering: box filtering, mean filtering, Gaussian filtering
Gin integrated Alipay payment
C language book rental management system
The failure rate is as high as 80%. What are the challenges on the way of enterprise digital transformation?
产业互联网则具备更大的发展潜能,具备更多的行业场景
LVGL 8.2 keyboard
Some problems and ideas of data embedding point
【MySQL从入门到精通】【高级篇】(四)MySQL权限管理与控制