案例一
背景:网站升级发现被百度收录了很多地址,无法直接进入新的网站,无差别定向
- 测试场景
server {
listen 80;
server_name tshop.mcaek.com;
index index.php index.html index.htm default.php default.htm default.html;
#access_log /var/log/nginx/host.access.log main;
location / {
try_files $uri $uri/ /index.html;
root /www/wwwroot/kafa/shop/dist/;
index index.html index.htm;
}
# location = /shop/([a-zA-Z0-9]*).html([\w]*)$ {
# 将shop下的所有资源都跳转到根
location ~ ^/shop(/.*)?$ {
return 301 http://tshop.mcaek.com/;
# return 301 http://server_name/;
}
# location = /shop/([a-zA-Z0-9]*)/([a-zA-Z0-9]*).html([\w]*)$ {
# return 301 http://tshop.mcake.com/;
# }
#location ^~ /api/ {
# proxy_pass http://hyperf.mcake-test.svc/;
#}
location /api/ {
proxy_pass http://hyperf.mcake-test.svc/api/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
- 生产场景
server {
listen 80;
server_name localhost;
index index.php index.html index.htm default.php default.htm default.html;
#access_log /var/log/nginx/host.access.log main;
location / {
try_files $uri $uri/ /index.html;
root /www/wwwroot/kafa/shop/dist/;
index index.html index.htm;
}
#location ^~ /api/ {
# proxy_pass http://hyperf.mcake-test.svc/;
#}
location ~ ^/shop(/.*)?$ {
return 301 https://www.mcake.com/;
}
location /api/ {
proxy_pass http://hyperf.mcake.svc/api/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
案例二
rewrite /shdrunion /#/vip-exchange?id=1 redirect;
rewrite /newUserActive /#/active?id=1579&type=2 redirect;
location ~* ^/api/.*$ {
proxy_pass http://test.openapi.mcake.com;
}
location / {
try_files $uri $uri/ /index.html;
#### kill cache
add_header Last-Modified $date_gmt;
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
if_modified_since off;
expires off;
etag off;
# 允许工厂ip访问
# allow 116.228.31.134;
# 允许兜礼测试
# allow 116.231.14.195;
# 拒绝所有
#deny all;
}
#location ~ /shdrunion/[0-9]+$ {
# rewrite /shdrunion/(\d+)$ https://test.h5.mcake.com/#/vip-exchange?id=$1;
#}
文档更新时间: 2024-05-08 13:22 作者:李延召