Commit 38185be0 authored by anarcat's avatar anarcat

simplify nginx configuration files

we get rid of the "advanced" configuration by moving the "upload
progress" logic into the vhost template itself

we do this to reduce code duplication
parent e6f3648e
......@@ -33,14 +33,68 @@ server {
ssl_prefer_server_ciphers on;
keepalive_timeout 70;
<?php print $extra_config; ?>
<?php print "include " . $server->include_path . "/nginx_common.conf;\n"; ?>
###
### Send all non-static requests to php-fpm, restricted to known php file.
###
location = /index.php {
add_header X-Engine "Aegir";
add_header X-Device "$device";
add_header X-Speed-Cache "$upstream_cache_status";
add_header X-Speed-Cache-UID "$cache_uid";
add_header X-Speed-Cache-Key "$key_uri";
add_header X-NoCache "$nocache_details";
add_header X-This-Proto "$http_x_forwarded_proto";
add_header X-Server-Name "$server_name";
###
### Use Nginx cache for all visitors.
###
set $nocache "";
if ( $nocache_details ~ (?:OctopusNCookie|Args|Skip) ) {
set $nocache "NoCache";
}
fastcgi_cache speed;
fastcgi_cache_methods GET HEAD; ### Nginx default, but added for clarity
fastcgi_cache_min_uses 1;
fastcgi_cache_key "$is_bot$device$host$request_method$key_uri$cache_uid$http_x_forwarded_proto$cookie_respimg";
fastcgi_cache_valid 200 10s;
fastcgi_cache_valid 302 1m;
fastcgi_cache_valid 301 403 404 5s;
fastcgi_cache_valid 500 502 503 504 1s;
fastcgi_ignore_headers Cache-Control Expires;
fastcgi_pass_header Set-Cookie;
fastcgi_pass_header X-Accel-Expires;
fastcgi_pass_header X-Accel-Redirect;
fastcgi_no_cache $cookie_OctopusNoCacheID $http_authorization $http_pragma $nocache;
fastcgi_cache_bypass $cookie_OctopusNoCacheID $http_authorization $http_pragma $nocache;
fastcgi_cache_use_stale error http_500 http_503 invalid_header timeout updating;
try_files $uri =404; ### check for existence of php file first
fastcgi_pass 127.0.0.1:9000;
<?php
$nginx_has_upload_progress = drush_get_option('nginx_has_upload_progress');
if ($nginx_has_upload_progress) {
print " include " . $server->include_path . "/nginx_advanced_include.conf;\n";
if ($server->nginx_has_upload_progress) {
print " track_uploads uploads 60s; ### required for upload progress\n";
}
?>
expires epoch;
}
else {
print " include " . $server->include_path . "/nginx_simple_include.conf;\n";
<?php
if ($server->nginx_has_upload_progress) {
?>
###
### Upload progress support.
### http://drupal.org/project/filefield_nginx_progress
### http://github.com/masterzen/nginx-upload-progress-module
###
location ~ (?:.*)/x-progress-id:(?:\w*) {
access_log off;
rewrite ^(.*)/x-progress-id:(\w*) $1?X-Progress-ID=$2;
}
location ^~ /progress {
access_log off;
report_uploads uploads;
}
<?php
}
?>
}
......
......@@ -38,7 +38,6 @@ else {
root <?php print "{$this->root}"; ?>;
<?php print $extra_config; ?>
<?php
$nginx_has_upload_progress = drush_get_option('nginx_has_upload_progress');
if ($this->redirection || $ssl_redirection) {
if ($ssl_redirection && !$this->redirection) {
// redirect aliases in non-ssl to the same alias on ssl.
......@@ -48,22 +47,70 @@ if ($this->redirection || $ssl_redirection) {
// redirect all aliases + main uri to the main https uri.
print "\n rewrite ^ https://{$this->uri}\$request_uri? permanent;\n";
}
elseif (!$ssl_redirection && $this->redirection) {
if ($server->nginx_has_upload_progress) {
print " include " . $server->include_path . "/nginx_advanced_include.conf;\n";
}
else {
print " include " . $server->include_path . "/nginx_simple_include.conf;\n";
}
}
}
else {
if ($server->nginx_has_upload_progress) {
print " include " . $server->include_path . "/nginx_advanced_include.conf;\n";
print " include " . $server->include_path . "/nginx_common.conf;\n";
?>
###
### Send all non-static requests to php-fpm, restricted to known php file.
###
location = /index.php {
add_header X-Engine "Aegir";
add_header X-Device "$device";
add_header X-Speed-Cache "$upstream_cache_status";
add_header X-Speed-Cache-UID "$cache_uid";
add_header X-Speed-Cache-Key "$key_uri";
add_header X-NoCache "$nocache_details";
add_header X-This-Proto "$http_x_forwarded_proto";
add_header X-Server-Name "$server_name";
###
### Use Nginx cache for all visitors.
###
set $nocache "";
if ( $nocache_details ~ (?:OctopusNCookie|Args|Skip) ) {
set $nocache "NoCache";
}
else {
print " include " . $server->include_path . "/nginx_simple_include.conf;\n";
fastcgi_cache speed;
fastcgi_cache_methods GET HEAD; ### Nginx default, but added for clarity
fastcgi_cache_min_uses 1;
fastcgi_cache_key "$is_bot$device$host$request_method$key_uri$cache_uid$http_x_forwarded_proto$cookie_respimg";
fastcgi_cache_valid 200 10s;
fastcgi_cache_valid 302 1m;
fastcgi_cache_valid 301 403 404 5s;
fastcgi_cache_valid 500 502 503 504 1s;
fastcgi_ignore_headers Cache-Control Expires;
fastcgi_pass_header Set-Cookie;
fastcgi_pass_header X-Accel-Expires;
fastcgi_pass_header X-Accel-Redirect;
fastcgi_no_cache $cookie_OctopusNoCacheID $http_authorization $http_pragma $nocache;
fastcgi_cache_bypass $cookie_OctopusNoCacheID $http_authorization $http_pragma $nocache;
fastcgi_cache_use_stale error http_500 http_503 invalid_header timeout updating;
try_files $uri =404; ### check for existence of php file first
fastcgi_pass 127.0.0.1:9000;
<?php
if ($server->nginx_has_upload_progress) {
print " track_uploads uploads 60s; ### required for upload progress\n";
}
?>
expires epoch;
}
<?php
if ($server->nginx_has_upload_progress) {
?>
###
### Upload progress support.
### http://drupal.org/project/filefield_nginx_progress
### http://github.com/masterzen/nginx-upload-progress-module
###
location ~ (?:.*)/x-progress-id:(?:\w*) {
access_log off;
rewrite ^(.*)/x-progress-id:(\w*) $1?X-Progress-ID=$2;
}
location ^~ /progress {
access_log off;
report_uploads uploads;
}
<?php
}
} ?>
}
......@@ -43,10 +43,8 @@ class Provision_Service_http_nginx extends Provision_Service_http_public {
}
function verify_server_cmd() {
provision_file()->copy(dirname(__FILE__) . '/nginx_advanced_include.conf', $this->server->include_path . '/nginx_advanced_include.conf');
$this->sync($this->server->include_path . '/nginx_advanced_include.conf');
provision_file()->copy(dirname(__FILE__) . '/nginx_simple_include.conf', $this->server->include_path . '/nginx_simple_include.conf');
$this->sync($this->server->include_path . '/nginx_simple_include.conf');
provision_file()->copy(dirname(__FILE__) . '/nginx_common.conf', $this->server->include_path . '/nginx_common.conf');
$this->sync($this->server->include_path . '/nginx_common.conf');
provision_file()->copy(dirname(__FILE__) . '/fastcgi_params.conf', $this->server->include_path . '/fastcgi_params.conf');
$this->sync($this->server->include_path . '/fastcgi_params.conf');
provision_file()->copy(dirname(__FILE__) . '/fastcgi_ssl_params.conf', $this->server->include_path . '/fastcgi_ssl_params.conf');
......
......@@ -63,10 +63,8 @@ class Provision_Service_http_nginx_ssl extends Provision_Service_http_ssl {
}
function verify_server_cmd() {
provision_file()->copy(dirname(dirname(__FILE__)) . '/nginx_advanced_include.conf', $this->server->include_path . '/nginx_advanced_include.conf');
$this->sync($this->server->include_path . '/nginx_advanced_include.conf');
provision_file()->copy(dirname(dirname(__FILE__)) . '/nginx_simple_include.conf', $this->server->include_path . '/nginx_simple_include.conf');
$this->sync($this->server->include_path . '/nginx_simple_include.conf');
provision_file()->copy(dirname(dirname(__FILE__)) . '/nginx_common.conf', $this->server->include_path . '/nginx_common.conf');
$this->sync($this->server->include_path . '/nginx_common.conf');
provision_file()->copy(dirname(dirname(__FILE__)) . '/fastcgi_params.conf', $this->server->include_path . '/fastcgi_params.conf');
$this->sync($this->server->include_path . '/fastcgi_params.conf');
provision_file()->copy(dirname(dirname(__FILE__)) . '/fastcgi_ssl_params.conf', $this->server->include_path . '/fastcgi_ssl_params.conf');
......
......@@ -507,45 +507,6 @@ location @nobots {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
###
### Send all non-static requests to php-fpm, restricted to known php file.
###
location = /index.php {
add_header X-Engine "Aegir";
add_header X-Device "$device";
add_header X-Speed-Cache "$upstream_cache_status";
add_header X-Speed-Cache-UID "$cache_uid";
add_header X-Speed-Cache-Key "$key_uri";
add_header X-NoCache "$nocache_details";
add_header X-This-Proto "$http_x_forwarded_proto";
add_header X-Server-Name "$server_name";
###
### Use Nginx cache for all visitors.
###
set $nocache "";
if ( $nocache_details ~ (?:OctopusNCookie|Args|Skip) ) {
set $nocache "NoCache";
}
fastcgi_cache speed;
fastcgi_cache_methods GET HEAD; ### Nginx default, but added for clarity
fastcgi_cache_min_uses 1;
fastcgi_cache_key "$is_bot$device$host$request_method$key_uri$cache_uid$http_x_forwarded_proto$cookie_respimg";
fastcgi_cache_valid 200 10s;
fastcgi_cache_valid 302 1m;
fastcgi_cache_valid 301 403 404 5s;
fastcgi_cache_valid 500 502 503 504 1s;
fastcgi_ignore_headers Cache-Control Expires;
fastcgi_pass_header Set-Cookie;
fastcgi_pass_header X-Accel-Expires;
fastcgi_pass_header X-Accel-Redirect;
fastcgi_no_cache $cookie_OctopusNoCacheID $http_authorization $http_pragma $nocache;
fastcgi_cache_bypass $cookie_OctopusNoCacheID $http_authorization $http_pragma $nocache;
fastcgi_cache_use_stale error http_500 http_503 invalid_header timeout updating;
try_files $uri =404; ### check for existence of php file first
fastcgi_pass 127.0.0.1:9000;
expires epoch;
}
###
### Send other known php requests/files to php-fpm without any caching.
###
......@@ -565,4 +526,3 @@ location ~* ^.+\.php$ {
#######################################################
### nginx.conf site standard vhost include end
#######################################################
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment