Skip to content

Instantly share code, notes, and snippets.

@lpcuong2106
Forked from josephbolus/1nginx.conf
Created August 26, 2020 14:52
Show Gist options
  • Save lpcuong2106/35ff7572fb88fe5a4df97dd584313f4b to your computer and use it in GitHub Desktop.
Save lpcuong2106/35ff7572fb88fe5a4df97dd584313f4b to your computer and use it in GitHub Desktop.

Revisions

  1. @josephbolus josephbolus renamed this gist Feb 16, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @josephbolus josephbolus revised this gist Feb 16, 2014. 5 changed files with 103 additions and 0 deletions.
    File renamed without changes.
    74 changes: 74 additions & 0 deletions location_optmz.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,74 @@
    location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    location = /favicon.ico {
    log_not_found off;
    access_log off;
    }

    location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
    }

    location ~ /\.svn/* {
    deny all;
    }

    location ~ /\.git/* {
    deny all;
    }

    location /nginx_status {
    stub_status on;
    access_log off;
    }

    location ~ /\. {
    deny all;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|swf)$ {
    expires max;
    log_not_found off;
    }

    location = /wp-admin {
    rewrite ^ /wp-admin/ permanent;
    }

    location ~ \.php(?:/|$) {
    if (!-f $document_root$fastcgi_script_name){
    rewrite ^ /index.php break;
    }

    location ~ ^/(status|ping)$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
    allow 127.0.0.1;
    deny all;
    }

    location ~ \.php$ {

    set $nocache "";
    if ($http_cookie ~ (comment_author_.*|wordpress_logged_in.*|wp-postpass_.*)) {
    set $nocache "Y";
    }

    fastcgi_pass php-fpm;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
    include fastcgi_params;

    fastcgi_cache_use_stale error timeout invalid_header http_500;
    fastcgi_cache_key $host$request_uri;
    fastcgi_cache example;
    fastcgi_cache_valid 200 1m;
    fastcgi_cache_bypass $nocache;
    fastcgi_no_cache $nocache;
    }
    27 changes: 27 additions & 0 deletions nginx-vhost.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    upstream php-fpm {
    server unix:/var/run/php5-fpm.sock;
    }

    server {
    listen 80;
    server_name www.example.com;
    rewrite ^ http://example.com$request_uri?;
    }

    server {
    listen 80;
    server_name example.com;

    root /var/www/example.com;
    index index.php;
    charset UTF-8;

    # Buffer log writes to speed up IO, or disable them altogether
    #access_log /var/log/nginx/example.com.access.log main buffer=16k;
    #error_log /var/log/nginx/example.com.error.log;
    access_log off;

    include location_optmz.conf;
    #include wp_super_cache.conf;

    }
    2 changes: 2 additions & 0 deletions wordpress-vhost → nginx-wordpress-vhost.conf
    Original file line number Diff line number Diff line change
    @@ -32,5 +32,7 @@
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    allow 127.0.0.1;
    deny all;
    }
    }
    File renamed without changes.
  3. @josephbolus josephbolus revised this gist Feb 16, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion wordpress-vhost
    Original file line number Diff line number Diff line change
    @@ -33,4 +33,4 @@
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    }
    }
  4. @josephbolus josephbolus revised this gist Feb 16, 2014. 2 changed files with 113 additions and 53 deletions.
    130 changes: 77 additions & 53 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -1,69 +1,93 @@
    # ---------------------------------------
    # Main Module
    # ---------------------------------------
    user nginx;
    worker_processes 8;
    error_log /var/log/nginx/error.log warn;
    pid /var/run/nginx.pid;

    events {

    # This number should be, at maximum, the number of CPU cores on your system.
    worker_processes 2;
    pid /var/run/nginx.pid;

    # Only log critical errors
    error_log /var/log/nginx/error.log crit;

    # ---------------------------------------
    # Events Module
    # ---------------------------------------
    events {
    worker_connections 8192;
    }

    multi_accept on;
    # Essential for linux optmized to serve many clients with each thread
    use epoll;
    }
    # ---------------------------------------
    # HTTP Core Module
    # ---------------------------------------

    http {
    #
    # Basic Settings
    #
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    #
    # Logging
    #
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';

    access_log /var/log/nginx/access.log main;

    sendfile on;
    keepalive_timeout 30;


    # Buffer log writes to speed up IO, or disable them altogether
    # access_log /var/log/nginx/access.log main buffer=16k;
    access_log off;


    #
    # Buffer + Timeouts
    #
    # Sendfile copies data between one FD and other from within the kernel.
    # More efficient than read() + write(), since the requires transferring data to and
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    types_hash_max_size 2048;

    # Close connections to the client if the client does not respond within a fixed period by various timeout directives.
    keepalive_timeout 30;
    keepalive_requests 10000;
    reset_timedout_connection on;
    client_body_timeout 10;
    send_timeout 2;

    #
    # File Cache Settings
    #

    # Cache
    open_file_cache max=200000 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 2;
    open_file_cache_errors on;


    # Gzip Compression
    gzip on;
    gzip_types text/css text/javascript application/x-javascript application/json text/xml;
    gzip_min_length 500;
    gzip_comp_level 5;

    fastcgi_buffer_size 32k;
    fastcgi_buffers 256 4k;

    root /var/www/wordpress;

    server {
    listen 80 default;
    server_name my-wordpress-test.com;

    index index.php;

    location / {
    try_files $uri $uri/ /index.php?$args;
    }

    location ~ /\. {
    deny all;
    }

    location ~ \.(css|js|jp(e)?g|gif|png|swf|ico)$ {
    expires 1y;
    }

    location = /wp-admin {
    rewrite ^ /wp-admin/ permanent;
    }

    include wp_super_cache;

    location ~ \.php(?:/|$) {
    if (!-f $document_root$fastcgi_script_name){
    rewrite ^ /index.php break;
    }

    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    }
    }

    # Document root
    root /user/share/nginx/www;

    #
    # Virtual Host Configs
    #

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;


    }
    36 changes: 36 additions & 0 deletions wordpress-vhost
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    server {
    listen 80 default;
    server_name www.domain.com domain.com;

    index index.php;

    location / {
    try_files $uri $uri/ /index.php?$args;
    }

    location ~ /\. {
    deny all;
    }

    location ~ \.(css|js|jp(e)?g|gif|png|swf|ico)$ {
    expires 1y;
    }

    location = /wp-admin {
    rewrite ^ /wp-admin/ permanent;
    }

    include wp_super_cache;

    location ~ \.php(?:/|$) {
    if (!-f $document_root$fastcgi_script_name){
    rewrite ^ /index.php break;
    }

    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    }
  5. @josephbolus josephbolus revised this gist Feb 16, 2014. 2 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  6. @josephbolus josephbolus revised this gist Feb 16, 2014. 2 changed files with 66 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions fastcgi_params.ini
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    fastcgi_param QUERY_STRING $query_string;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param CONTENT_TYPE $content_type;
    fastcgi_param CONTENT_LENGTH $content_length;

    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    fastcgi_param REQUEST_URI $request_uri;
    fastcgi_param DOCUMENT_URI $document_uri;
    fastcgi_param DOCUMENT_ROOT $document_root;
    fastcgi_param SERVER_PROTOCOL $server_protocol;
    fastcgi_param HTTPS $https if_not_empty;

    fastcgi_param GATEWAY_INTERFACE CGI/1.1;
    fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

    fastcgi_param REMOTE_ADDR $remote_addr;
    fastcgi_param REMOTE_PORT $remote_port;
    fastcgi_param SERVER_ADDR $server_addr;
    fastcgi_param SERVER_PORT $server_port;
    fastcgi_param SERVER_NAME $server_name;

    # PHP only, required if PHP was built with --enable-force-cgi-redirect
    fastcgi_param REDIRECT_STATUS 200;
    43 changes: 43 additions & 0 deletions wp_super_cache.ini
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    set $supercacheuri "";
    set $supercachefile "$document_root/wp-content/cache/supercache/${http_host}${uri}index.html.gz";
    if (-e $supercachefile) {
    set $supercacheuri "/wp-content/cache/supercache/${http_host}${uri}index.html.gz";
    }

    # If this is a POST request, pass the request onto WordPress.
    if ($request_method = POST) {
    set $supercacheuri "";
    }

    # If there is a query string, serve the uncached version.
    if ($query_string) {
    set $supercacheuri "";
    }

    # Logged in users and those who have posted a comment get the non-cached version.
    if ($http_cookie ~* comment_author_|wordpress_logged_in|wp-postpass_) {
    set $supercacheuri "";
    }

    # Mobile browsers get the non-cached version.
    # Wastes CPU cycles if there isn't a mobile browser WP theme for the site.
    if ($http_x_wap_profile) {
    set $supercacheuri "";
    }

    if ($http_profile) {
    set $supercacheuri "";
    }

    if ($http_user_agent ~* (2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800)) {
    set $supercacheuri "";
    }

    if ($http_user_agent ~* (w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-)) {
    set $supercacheuri "";
    }

    # Stop processing if the supercache file is valid.
    if ($supercacheuri) {
    rewrite ^ $supercacheuri break;
    }
  7. @josephbolus josephbolus created this gist Feb 16, 2014.
    69 changes: 69 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    user nginx;
    worker_processes 8;
    error_log /var/log/nginx/error.log warn;
    pid /var/run/nginx.pid;

    events {
    worker_connections 8192;
    }

    http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';

    access_log /var/log/nginx/access.log main;

    sendfile on;
    keepalive_timeout 30;

    gzip on;
    gzip_types text/css text/javascript application/x-javascript application/json text/xml;
    gzip_min_length 500;
    gzip_comp_level 5;

    fastcgi_buffer_size 32k;
    fastcgi_buffers 256 4k;

    root /var/www/wordpress;

    server {
    listen 80 default;
    server_name my-wordpress-test.com;

    index index.php;

    location / {
    try_files $uri $uri/ /index.php?$args;
    }

    location ~ /\. {
    deny all;
    }

    location ~ \.(css|js|jp(e)?g|gif|png|swf|ico)$ {
    expires 1y;
    }

    location = /wp-admin {
    rewrite ^ /wp-admin/ permanent;
    }

    include wp_super_cache;

    location ~ \.php(?:/|$) {
    if (!-f $document_root$fastcgi_script_name){
    rewrite ^ /index.php break;
    }

    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    }
    }