Мне сложно понять, как уменьшить количество «повторяющихся строк» для моей конфигурации NGinx, просто чтобы изменить одно свойство:
server {
#listen [::]:443 ipv6only=on; ## listen for ipv6
listen 443;
server_name my.website.com;
access_log /var/log/nginx/my.website.com_access.log;
error_log /var/log/nginx/my.website.com_error.log;
ssl on;
ssl_certificate /etc/nginx/website.com/cert.pem;
ssl_certificate_key /etc/nginx/website.com/cert.key;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP:!kEDH;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:9010;
client_max_body_size 1m; # I limit all the file upload to 1 Mo
error_page 413 =200 https://my.website.com/errors/413; # I send back a 200 HTTP STATUS because Chrome crashes with a 413 (lol)
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# Now, for the two next locations, I will change the body size to 10Mo
location = /picture/create {
proxy_pass http://127.0.0.1:9010;
client_max_body_size 10m; # Here,
error_page 413 =200 https://my.website.com/errors/413;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ^/picture/([0-9]+)/edit$ {
proxy_pass http://127.0.0.1:9010;
client_max_body_size 10m; # And here
error_page 413 =200 https://my.website.com/errors/413;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Я хотел бы знать, можно ли:
Спасибо за вашу помощь.
Один из способов сделать это - создать файл и «включить» его. Например, создайте новый файл с именем 'standard_include.conf' со следующим текстом в нем.
proxy_pass http://127.0.0.1:9010;
error_page 413 =200 https://my.website.com/errors/413;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Затем используйте стандартную конфигурацию:
#listen [::]:443 ipv6only=on; ## listen for ipv6
listen 443;
server_name my.website.com;
access_log /var/log/nginx/my.website.com_access.log;
error_log /var/log/nginx/my.website.com_error.log;
ssl on;
ssl_certificate /etc/nginx/website.com/cert.pem;
ssl_certificate_key /etc/nginx/website.com/cert.key;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP:!kEDH;
ssl_prefer_server_ciphers on;
location / {
include standard_include.conf;
client_max_body_size 1m; # I limit all the file upload to 1 Mo
}
# Now, for the two next locations, I will change the body size to 10Mo
location = /picture/create {
include standard_include.conf;
client_max_body_size 10m; # Here,
}
location ^/picture/([0-9]+)/edit$ {
include standard_include.conf;
client_max_body_size 10m; # And here
}