Advertisement
mikeg_de

Nginx-Configuration with Fast-CGI, Mod Pagespeed, CDN CORS

Nov 15th, 2014
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. # Find full tutorial at: http://mikeg.de/project/cloud-nginx-server-wordpress/
  2.  
  3. worker_processes 1;
  4. pid /var/run/nginx.pid;
  5.  
  6. events {
  7. worker_connections 1024;
  8. }
  9.  
  10.  
  11. http {
  12. include mime.types;
  13. include pagespeed_libraries.conf;
  14. include fastcgi.conf;
  15. default_type application/octet-stream;
  16.  
  17. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  18. '$status $body_bytes_sent "$http_referer" '
  19. '"$http_user_agent" "$http_x_forwarded_for"';
  20.  
  21. log_format cache '$remote_addr - $remote_user [$time_local] '
  22. '"$request" $status $body_bytes_sent '
  23. '"$http_referer" "$http_user_agent" nocache:$skip_cache '
  24. '$upstream_cache_status';
  25.  
  26. access_log /var/log/nginx/access.log main;
  27. error_log /var/log/nginx/error.log debug;
  28.  
  29. sendfile on;
  30. keepalive_timeout 65;
  31. tcp_nodelay on;
  32.  
  33. server_names_hash_bucket_size 128;
  34.  
  35. pagespeed On;
  36. pagespeed FileCachePath /var/cache/nginx/ngx_pagespeed;
  37. pagespeed ModPagespeedRewriteLevel CoreFilters;
  38.  
  39. # Use gzip compression
  40. # gzip_static on; # Uncomment if you compiled Nginx using --with-http_gzip_static_module
  41. gzip on;
  42. gzip_vary on;
  43. gzip_proxied any;
  44. gzip_comp_level 6;
  45. gzip_buffers 16 8k;
  46. gzip_http_version 1.1;
  47. gzip_types text/plain text/css text/javascript text/xml application/json application/x-javascript application/xml application/xm$ application/xml+rss image/png image/gif image/jpeg;
  48. gzip_disable "MSIE [1-6]\.(?!.*SV1)";
  49.  
  50. # Fast-CGI cache
  51. fastcgi_cache_path /var/cache/nginx/wordpress levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
  52. fastcgi_cache_path /var/cache/nginx/system levels=1:2 keys_zone=SYSTEM:100m inactive=60m;
  53. fastcgi_cache_key "$scheme$request_method$host$request_uri";
  54. fastcgi_cache_use_stale error timeout invalid_header http_500;
  55.  
  56. add_header X-Cache $upstream_cache_status;
  57.  
  58. server {
  59. listen 80;
  60. server_name YOUR_AMAZON_IP;
  61. root /srv/system/;
  62. index index.html index.htm;
  63.  
  64. location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; }
  65. location ~ "^/ngx_pagespeed_static/" { }
  66. location ~ "^/ngx_pagespeed_beacon$" { }
  67. location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all; }
  68. location /ngx_pagespeed_global_statistics { allow 127.0.0.1; deny all; }
  69. location /ngx_pagespeed_message { allow 127.0.0.1; deny all; }
  70. location /pagespeed_console { allow 127.0.0.1; deny all; }
  71.  
  72. location ~ \.php$ {
  73. fastcgi_cache SYSTEM;
  74. fastcgi_cache_valid 200 60m;
  75.  
  76. include fastcgi_params;
  77. fastcgi_pass unix:/var/run/php5-fpm.sock;
  78. fastcgi_index index.php;
  79. fastcgi_param SCRIPT_FILENAME $request_filename;
  80. }
  81.  
  82. # Include security configuration
  83. include sites-available/security.conf;
  84. }
  85.  
  86. # Normalization
  87. server {
  88. listen 80;
  89.  
  90. # On production sites add IP for good SEO
  91. server_name www.YOUR_AMAZON_DNS;
  92. return 301 $scheme://mikeg.de$request_uri;
  93. }
  94.  
  95. server {
  96. listen 80 default_server;
  97. server_name YOUR_AMAZON_DNS;
  98. root /srv/wordpress/;
  99. index index.php;
  100.  
  101. # Turned off since W3 Total Cache will handle caching
  102. # and mod_pagespeed won't enhance WP: http://wordpress.org/support/topic/plugin-w3-total-cache-googles-mod_pagespeed-and-w3
  103. pagespeed Off;
  104.  
  105. access_log /var/log/nginx/wordpress.log cache;
  106. error_log /var/log/nginx/wordpress.error.log debug;
  107.  
  108. rewrite_log on;
  109.  
  110. # Include nginx.conf made by W3 Total Cache
  111. #include /srv/wordpress/nginx.conf;
  112.  
  113. # Include common WordPress configuration
  114. include sites-available/wordpress-common.conf;
  115.  
  116. # Include security configuration
  117. include sites-available/security.conf;
  118.  
  119. # Manual rewrites
  120. # rewrite ^/your-url.* http://$server_name/ permanent;
  121. }
  122.  
  123. # CDN Sub-Domain configuration with CORS
  124. server {
  125. listen 80;
  126. server_name cdn-01.YOUR_AMAZON_DNS;
  127. root /srv/wordpress/;
  128.  
  129. access_log /var/log/nginx/cdn.wordpress.access.log;
  130. error_log /var/log/nginx/cdn.wordpress.error.log;
  131.  
  132. # Include CDN configuration
  133. include sites-available/cdn.conf;
  134. }
  135.  
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement