我很难find如何减less我的NGinxconfiguration“重复行”,只是改变一个属性:
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; } }
我想知道是否有可能:
谢谢你的帮助。
你可以做的一个方法是创build一个文件并“包含”它。 例如,创build一个名为“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;
然后把你的标准configuration为:
#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 }