Last active
April 27, 2021 17:53
-
-
Save crosstyan/14ada68b4cea063d40198df7af5152b7 to your computer and use it in GitHub Desktop.
a nginx config file for me
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| server{ | |
| listen 80; | |
| server_name blog.moe.wtf; | |
| return 301 https://blog.moe.wtf$request_uri; | |
| } | |
| server{ | |
| listen 443 quic reuseport; | |
| listen 443 ssl http2; | |
| server_name blog.moe.wtf; | |
| root /var/www/moe-blog; | |
| index index.php index.html; | |
| ssl_certificate /etc/nginx/ssl/wildcard.moe.crt; | |
| ssl_certificate_key /etc/nginx/ssl/wildcard.moe.key; | |
| ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; | |
| ssl_prefer_server_ciphers on; | |
| ssl_session_cache shared:SSL:50m; | |
| ssl_session_timeout 1d; | |
| add_header alt-svc 'h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400'; | |
| # Pagespeed | |
| pagespeed RewriteLevel CoreFilters; | |
| pagespeed EnableFilters rewrite_css,combine_css; | |
| pagespeed EnableFilters rewrite_javascript,combine_javascript; | |
| pagespeed EnableFilters collapse_whitespace,combine_heads,remove_quotes,trim_urls; | |
| pagespeed EnableFilters elide_attributes,extend_cache,insert_dns_prefetch; | |
| pagespeed EnableFilters lazyload_images,resize_rendered_image_dimensions; | |
| # Rewrite for Wordpress | |
| location / { | |
| if (-f $request_filename/index.html){ | |
| rewrite (.*) $1/index.html break; | |
| } | |
| if (-f $request_filename/index.php){ | |
| rewrite (.*) $1/index.php; | |
| } | |
| if (!-f $request_filename){ | |
| rewrite (.*) /index.php; | |
| } | |
| } | |
| rewrite /wp-admin$ $scheme://$host$uri/ permanent; | |
| # PHP config | |
| # PHP is runnnig in docker | |
| location ~ \.php$ { | |
| try_files $uri =404; | |
| fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
| fastcgi_pass localhost:9000; | |
| fastcgi_index index.php; | |
| include fastcgi_params; | |
| fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
| fastcgi_param PATH_INFO $fastcgi_path_info; | |
| fastcgi_cache_bypass $skip_cache; | |
| fastcgi_no_cache $skip_cache; | |
| fastcgi_cache WORDPRESS; | |
| fastcgi_cache_valid 60m; | |
| } | |
| # FastCGI and something else | |
| set $skip_cache 0; | |
| # POST requests and urls with a query string should always go to PHP | |
| if ($request_method = POST) { | |
| set $skip_cache 1; | |
| } | |
| if ($query_string != "") { | |
| set $skip_cache 1; | |
| } | |
| # Don't cache uris containing the following segments | |
| if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") { | |
| set $skip_cache 1; | |
| } | |
| # Don't use the cache for logged in users or recent commenters | |
| if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { | |
| set $skip_cache 1; | |
| } | |
| location ~ /purge(/.*) { | |
| fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1"; | |
| } | |
| location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { | |
| access_log off; log_not_found off; expires max; | |
| } | |
| location = /robots.txt { access_log off; log_not_found off; } | |
| location ~ /\. { deny all; access_log off; log_not_found off; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| user nginx; | |
| worker_processes auto; | |
| pid /run/nginx.pid; | |
| load_module /etc/nginx/modules/ngx_http_brotli_filter_module.so; | |
| load_module /etc/nginx/modules/ngx_http_brotli_static_module.so; | |
| load_module /etc/nginx/modules/ngx_pagespeed.so; | |
| load_module /etc/nginx/modules/ngx_http_image_filter_module.so; | |
| load_module /etc/nginx/modules/ngx_http_js_module.so; | |
| load_module /etc/nginx/modules/ngx_stream_js_module.so; | |
| events { | |
| worker_connections 768; | |
| # multi_accept on; | |
| } | |
| http { | |
| ## | |
| # Basic Settings | |
| ## | |
| sendfile on; | |
| tcp_nopush on; | |
| tcp_nodelay on; | |
| keepalive_timeout 65; | |
| types_hash_max_size 2048; | |
| # server_tokens off; | |
| # server_names_hash_bucket_size 64; | |
| # server_name_in_redirect off; | |
| include /etc/nginx/mime.types; | |
| default_type application/octet-stream; | |
| ## | |
| # SSL Settings | |
| ## | |
| ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE | |
| ssl_prefer_server_ciphers on; | |
| ## | |
| # Logging Settings | |
| ## | |
| access_log /var/log/nginx/access.log; | |
| error_log /var/log/nginx/error.log; | |
| ## | |
| # Gzip Settings | |
| ## | |
| gzip on; | |
| gzip_vary on; | |
| gzip_proxied any; | |
| gzip_comp_level 6; | |
| gzip_buffers 16 8k; | |
| gzip_http_version 1.1; | |
| gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; | |
| # | |
| # Brotli | |
| # | |
| brotli on; | |
| brotli_comp_level 6; | |
| brotli_static on; | |
| brotli_types application/atom+xml application/javascript application/json application/rss+xml | |
| application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype | |
| application/x-font-ttf application/x-javascript application/xhtml+xml application/xml | |
| font/eot font/opentype font/otf font/truetype image/svg+xml image/vnd.microsoft.icon | |
| image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml; | |
| # | |
| # FastCGI Cache | |
| # | |
| fastcgi_cache_path /var/run/nginx-cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m; | |
| fastcgi_cache_key "$scheme$request_method$host$request_uri"; | |
| fastcgi_cache_use_stale error timeout invalid_header http_500; | |
| fastcgi_ignore_headers Cache-Control Expires Set-Cookie; | |
| # | |
| # Pagespeed | |
| # | |
| pagespeed on; | |
| pagespeed PreserveUrlRelativity on; | |
| pagespeed FileCachePath "/var/cache/pagespeed/"; | |
| ## | |
| # Virtual Host Configs | |
| ## | |
| include /etc/nginx/sites-enabled/*.conf; | |
| include /etc/nginx/conf.d/*.conf; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment