1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00

nginx: optimize locations

This commit is contained in:
Izorkin 2022-11-01 20:17:41 +03:00
parent 443186ff40
commit dd72b79a81
No known key found for this signature in database
GPG key ID: 1436C1B3F3679F09

52
dist/nginx.conf vendored
View file

@ -65,65 +65,53 @@ server {
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml image/x-icon; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/svg+xml image/x-icon;
location / { location / {
try_files $uri @proxy; add_header Strict-Transport-Security 'max-age=63072000; includeSubDomains';
} }
# If Docker is used for deployment and Rails serves static files, # If Docker is used for deployment and Rails serves static files,
# then needed must replace line `try_files $uri =404;` with `try_files $uri @proxy;`. # then needed must uncomment line `try_files $uri @mastodon;`.
location = /sw.js { location ^~ /assets/ {
add_header Cache-Control "public, max-age=604800, must-revalidate"; #try_files $uri @mastodon;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
try_files $uri =404;
}
location ~ ^/assets/ {
add_header Cache-Control "public, max-age=2419200, must-revalidate"; add_header Cache-Control "public, max-age=2419200, must-revalidate";
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"; add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
try_files $uri =404;
} }
location ~ ^/avatars/ { location ^~ /avatars/ {
#try_files $uri @mastodon;
add_header Cache-Control "public, max-age=2419200, must-revalidate"; add_header Cache-Control "public, max-age=2419200, must-revalidate";
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"; add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
try_files $uri =404;
} }
location ~ ^/emoji/ { location ^~ /emoji/ {
#try_files $uri @mastodon;
add_header Cache-Control "public, max-age=2419200, must-revalidate"; add_header Cache-Control "public, max-age=2419200, must-revalidate";
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"; add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
try_files $uri =404;
} }
location ~ ^/headers/ { location ^~ /headers/ {
#try_files $uri @mastodon;
add_header Cache-Control "public, max-age=2419200, must-revalidate"; add_header Cache-Control "public, max-age=2419200, must-revalidate";
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"; add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
try_files $uri =404;
} }
location ~ ^/packs/ { location ^~ /ocr/ {
#try_files $uri @mastodon;
add_header Cache-Control "public, max-age=2419200, must-revalidate"; add_header Cache-Control "public, max-age=2419200, must-revalidate";
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"; add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
try_files $uri =404;
} }
location ~ ^/shortcuts/ { location ^~ /packs/ {
#try_files $uri @mastodon;
add_header Cache-Control "public, max-age=2419200, must-revalidate"; add_header Cache-Control "public, max-age=2419200, must-revalidate";
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"; add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
try_files $uri =404;
} }
location ~ ^/sounds/ { location ^~ /system/ {
add_header Cache-Control "public, max-age=2419200, must-revalidate"; #try_files $uri @mastodon;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
try_files $uri =404;
}
location ~ ^/system/ {
add_header Cache-Control "public, max-age=2419200, immutable"; add_header Cache-Control "public, max-age=2419200, immutable";
add_header Content-Security-Policy "default-src 'none'; form-action 'none'";
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains"; add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
add_header X-Content-Type-Options nosniff; add_header X-Content-Type-Options nosniff;
add_header Content-Security-Policy "default-src 'none'; form-action 'none'";
try_files $uri =404;
} }
location ^~ /api/v1/streaming { location ^~ /api/v1/streaming {
@ -140,12 +128,10 @@ server {
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade; proxy_set_header Connection $connection_upgrade;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains";
tcp_nodelay on; tcp_nodelay on;
} }
location @proxy { location @mastodon {
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@ -169,5 +155,7 @@ server {
tcp_nodelay on; tcp_nodelay on;
} }
# If Docker is used for deployment and Rails serves static files,
# then needed must remove the 404 parameter.
error_page 404 500 501 502 503 504 /500.html; error_page 404 500 501 502 503 504 /500.html;
} }