当前位置:网站首页>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
边栏推荐
- Combined with case: the usage of the lowest API (processfunction) in Flink framework
- LVGL 8.2 Menu
- Practical puzzle solving | how to extract irregular ROI regions in opencv
- 产业互联网则具备更大的发展潜能,具备更多的行业场景
- The implementation of OSD on rk1126 platform supports color translucency and multi-channel support for Chinese
- Digi XBee 3 rf: 4 protocols, 3 packages, 10 major functions
- 潘多拉 IOT 开发板学习(RT-Thread)—— 实验3 按键实验(学习笔记)
- Programmer turns direction
- No servers available for service: xxxx
- Five minutes of machine learning every day: how to use matrix to represent the sample data of multiple characteristic variables?
猜你喜欢

【C语言】指针笔试题

Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing

开发中常见问题总结

软件测试之测试评估

Real time data warehouse

一文概览2D人体姿态估计

Query optimizer for SQL optimization

Docker compose public network deployment redis sentinel mode

leetcode:6110. 网格图中递增路径的数目【dfs + cache】

LVGL 8.2 Line
随机推荐
Pandora IOT development board learning (RT thread) - Experiment 3 button experiment (learning notes)
Sqlserver functions, creation and use of stored procedures
Wt588f02b-8s (c006_03) single chip voice IC scheme enables smart doorbell design to reduce cost and increase efficiency
Chapter 16 string localization and message Dictionary (2)
openresty 重定向
Scratch Castle Adventure Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
codeforce:C. Sum of Substrings【边界处理 + 贡献思维 + 灵光一现】
leetcode:6109. Number of people who know the secret [definition of DP]
Comment configurer un accord
Five minutes of machine learning every day: how to use matrix to represent the sample data of multiple characteristic variables?
LVGL 8.2 List
Ranking list of databases in July: mongodb and Oracle scores fell the most
IO流:节点流和处理流详细归纳。
Practical puzzle solving | how to extract irregular ROI regions in opencv
MySQL stored procedure exercise
[MySQL from introduction to proficiency] [advanced chapter] (IV) MySQL permission management and control
【C语言】指针笔试题
LVGL 8.2 Draw label with gradient color
毕业季-个人总结
Docker compose public network deployment redis sentinel mode