当前位置:网站首页>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
边栏推荐
- Opencv3.2 and opencv2.4 installation
- Map of mL: Based on Boston house price regression prediction data set, an interpretable case is realized by using the map value to the LIR linear regression model
- Leetcode T48: rotating images
- Solutions aux problèmes d'utilisation de l'au ou du povo 2 dans le riz rouge k20pro MIUI 12.5
- Visual Studio调试方式详解
- C language course design questions
- Summary of common problems in development
- Transplant tinyplay for imx6q development board QT system
- Xcode abnormal pictures cause IPA packet size problems
- 函数计算异步任务能力介绍 - 任务触发去重
猜你喜欢
Wt588f02b-8s (c006_03) single chip voice IC scheme enables smart doorbell design to reduce cost and increase efficiency
leetcode:6109. Number of people who know the secret [definition of DP]
Five minutes per day machine learning: use gradient descent to complete the fitting of multi feature linear regression model
[information retrieval] link analysis
Compile oglpg-9th-edition source code with clion
LVGL 8.2 Draw label with gradient color
SAIC Maxus officially released its new brand "mifa", and its flagship product mifa 9 was officially unveiled!
Explain of SQL optimization
Alcohol driving monitoring system based on stm32+ Huawei cloud IOT design
leecode学习笔记-约瑟夫问题
随机推荐
PLC模拟量输入 模拟量转换FC S_ITR (CODESYS平台)
5g TV cannot become a competitive advantage, and video resources become the last weapon of China's Radio and television
Visual Studio调试方式详解
Wt588f02b-8s (c006_03) single chip voice IC scheme enables smart doorbell design to reduce cost and increase efficiency
No servers available for service: xxxx
openresty 限流
Data Lake (13): spark and iceberg integrate DDL operations
C language small commodity management system
Kubernets Pod 存在 Finalizers 一直处于 Terminating 状态
(1) The standard of performance tuning and the correct posture for tuning - if you have performance problems, go to the heapdump performance community!
韩国AI团队抄袭震动学界!1个导师带51个学生,还是抄袭惯犯
Real time data warehouse
5G电视难成竞争优势,视频资源成中国广电最后武器
MySQL triggers
Progress in architecture
内存管理总结
C language achievement management system for middle school students
Ultrasonic distance meter based on 51 single chip microcomputer
阿里被裁员工,找工作第N天,猎头又传来噩耗...
尊重他人的行为