還是上邊的那個問題,有一些場景,我們可能需要有自己的請求路徑(不使用默認的location /)
比如api 與業務系統的請求路徑是分開的(前后端分開部署的系統是最典型的)
解決方法
一樣還是通過url rewrite,需要解決的問題就是比以前的多了一條,我們的rewrite 也是多了一條
參考nginx 配置
worker_processes 1;
user root;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
lua_code_cache off;
gzip on;
resolver 127.0.0.11 8.8.8.8 ipv6=off;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
upstream s3app {
server s3:9000;
}
server {
listen 80;
server_name localhost;
charset utf-8;
root html;
index index.html index.htm;
default_type text/html;
location /apps/ {
default_type text/html;
index index.html index.htm;
rewrite ^/apps/([a-zA-Z0-9]+)$ /apps/$1/ permanent;
rewrite ^/apps/([a-zA-Z0-9]+)/$ /$1/index.html break;
rewrite ^/apps/(.*) /$1 break;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $remote_addr;
client_body_buffer_size 10M;
client_max_body_size 10G;
proxy_buffers 1024 4k;
proxy_read_timeout 300;
proxy_next_upstream error timeout http_404;
proxy_pass http://s3app;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
- 說明
我們約定s3 的請求都走apps,第一條rewrite 是進行添加/ 方便后續處理(使用permanent)
第二條rewrite 是index.html的配置,第三條是對於其他請求資源的rewrite,請求到實際s3 bucket的
位置