![合并 nginx 位置块](https://linux22.com/image/755657/%E5%90%88%E5%B9%B6%20nginx%20%E4%BD%8D%E7%BD%AE%E5%9D%97.png)
有没有办法让/api/*
和具有相同的配置/api/private/*
?我尝试将/api/private/
位置块放在 的块内/api/
,但 会返回 404。/api/private/
谢谢。
worker_processes 5;
error_log /dev/stderr info;
pid /tmp/nginx.pid;
daemon off;
events {
worker_connections 4096; ## Default: 1024
}
http {
access_log /dev/stdout combined;
root /assets;
server_tokens off;
server {
listen 8080 default;
server_name _;
server_tokens off;
client_body_timeout 12;
client_header_timeout 12;
keepalive_timeout 15;
send_timeout 10;
include /mime.types;
gzip on;
gzip_http_version 1.0;
gzip_comp_level 5;
gzip_min_length 512;
gzip_buffers 4 8k;
gzip_proxied any;
gzip_types
# text/html is always compressed by HttpGzipModule
text/css
text/plain
text/x-component
application/javascript
application/json
application/xml
application/xhtml+xml
application/x-font-ttf
application/x-font-opentype
application/vnd.ms-fontobject
image/svg+xml
image/x-icon;
client_body_temp_path /tmp/clientbody;
proxy_temp_path /tmp/proxy;
fastcgi_temp_path /tmp/fastcgi;
uwsgi_temp_path /tmp/uwsgi;
scgi_temp_path /tmp/scgi;
# no framing
add_header X-Frame-Options DENY;
# no mime sniff
add_header X-Content-Type-Options nosniff;
# enable browser XSS protection
add_header X-XSS-Protection "1; mode=block";
# Remove Referer headers
add_header Referrer-Policy "no-referrer";
# Add CORS headers
add_header Access-Control-Allow-Origin "https://$host";
add_header Access-Control-Allow-Methods "GET,POST,HEAD";
# Add Feature Policy header
add_header Feature-Policy "geolocation 'none'; midi 'none'; notifications 'none'; push 'none'; sync-xhr 'none'; microphone 'none'; camera 'none'; magnetometer 'none'; gyroscope 'none'; speaker 'none'; vibrate 'none'; fullscreen 'none'; payment 'none';";
if ($request_method !~ ^(GET|HEAD|POST)$ ) {
return 444;
}
location ~* \.(?:manifest|appcache|html?|xml|css|js|jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1d;
add_header Cache-Control "private";
}
location /_health {
access_log off;
allow 127.0.0.1;
deny all;
stub_status;
}
location /api/private/ {
proxy_read_timeout 30m;
send_timeout 30m;
client_max_body_size 1000M;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $http_cf_connecting_ip;
proxy_pass http://api:8080/;
}
location /api/ {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $http_cf_connecting_ip;
proxy_pass http://api:8080/;
}
}
}
理想情况下我想这样做:
location /api/ {
location /api/private/ {
proxy_read_timeout 30m;
send_timeout 30m;
client_max_body_size 1000M;
}
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $http_cf_connecting_ip;
proxy_pass http://api:8080/;
}