Last active
July 18, 2018 21:12
-
-
Save evemilano/78d32ff73fb7ca203ffd1319824414c8 to your computer and use it in GitHub Desktop.
Nginx basic server block with HTTPS and Cache
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
fastcgi_cache_path /etc/nginx/cache/1 levels=1:2 keys_zone=CACHESITO:10m max_size=50m inactive=1440m use_temp_path=off; | |
fastcgi_cache_key "$scheme$request_method$host$request_uri"; | |
add_header X-Cache $upstream_cache_status; | |
server { | |
listen 80; | |
listen [::]:80; | |
#redirect to HTTPS | |
server_name miosito.com www.miosito.com; | |
rewrite ^(.*) https://miosito.com$1 permanent; | |
} | |
server { | |
listen 443 ssl http2; | |
listen [::]:443 ssl http2; | |
ssl on; | |
ssl_certificate /etc/letsencrypt/live/miosito.com-0001/fullchain.pem; # managed by Certbot | |
ssl_certificate_key /etc/letsencrypt/live/miosito.com-0001/privkey.pem; # managed by Certbot | |
#redirect www to not-www | |
server_name www.giobrazo.com; | |
rewrite ^(.*) https://giobrazo.com$1 permanent; | |
} | |
server { | |
listen 443 ssl http2; | |
listen [::]:443 ssl http2; | |
ssl on; | |
ssl_prefer_server_ciphers on; | |
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; | |
ssl_certificate /etc/letsencrypt/live/giobrazo.com-0001/fullchain.pem; # managed by Certbot | |
ssl_certificate_key /etc/letsencrypt/live/giobrazo.com-0001/privkey.pem; # managed by Certbot | |
server_name miosito.com; | |
root /var/www/html/miosito; | |
# Add trailing slash to */wp-admin requests. | |
rewrite /wp-admin$ $scheme://$host$uri/ permanent; | |
# Add index.php to the list if you are using PHP | |
index index.php index.html index.htm index.nginx-debian.html; | |
# CACHE | |
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { | |
expires 365d; | |
} | |
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/|/sw.js|/manifest.json|/xmlrpc.php|wp-.*.php|/feed/|index.php|robots.txt|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 / { | |
# This is cool because no php is touched for static content. | |
# include the "?$args" part so non-default permalinks doesn't break when using query string | |
try_files $uri $uri/ /index.php?$args; | |
} | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
location ~ \.php$ { | |
include snippets/fastcgi-php.conf; | |
fastcgi_pass unix:/run/php/php7.0-fpm.sock; | |
fastcgi_cache CACHESITO; | |
fastcgi_cache_valid 200 302 1440m; #minuti | |
fastcgi_cache_valid 404 1m; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Guida alla configurazione di un web server LEMP: https://www.evemilano.com/setup-lemp-server/