Advertisement
Guest User

nginx.conf

a guest
Feb 19th, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nginx 3.51 KB | None | 0 0
  1. user nginx;
  2. worker_processes auto;
  3. error_log /var/log/nginx/error.log;
  4. pid /run/nginx.pid;
  5.  
  6. events {
  7.     worker_connections 1024;
  8. }
  9.  
  10. http {
  11.     log_format  main  '$remote_addr - $remote_user [$time_local] $upstream_cache_status "$request" '
  12.                       '$status $body_bytes_sent "$http_referer" '
  13.                       '"$http_user_agent" "$http_x_forwarded_for"';
  14.     access_log  /var/log/nginx/access.log  main;
  15.  
  16.     sendfile            on;
  17.     tcp_nopush          on;
  18.     tcp_nodelay         on;
  19.     keepalive_timeout   65;
  20.     types_hash_max_size 4096;
  21.  
  22.     include             /etc/nginx/mime.types;
  23.     default_type        application/octet-stream;
  24.  
  25.     proxy_cache_path /var/cache/fdroid levels=1:2 keys_zone=fdroid_cache:10m max_size=12g
  26.                  inactive=24h use_temp_path=off;
  27.  
  28.  
  29.     map $request_uri $max_age {
  30.     default             600;    # 10 min default (for html and the index files)
  31.     ~^/assets/          43200;  # 12 hours for website assets
  32.     ~^/js/              43200; 
  33.     ~^/css/             43200; 
  34.     ~^/FDroid.apk           86400;  # 1 day for the F-Droid apk
  35.     ~^/repo/icons.*\.\d+\.png   604800; # 1 week for repo files with version number in name
  36.     ~^/repo/.*\.apk$        604800;
  37.     ~^/repo/.*\.apk.asc$        604800;
  38.     ~^/repo/.*\.tar.gz$     604800;
  39.     ~^/repo/.*/icon.png$        86400;  # 1 day for icons and screenshots without version number
  40.     ~^/repo/.*/phoneScreenshots/    86400;
  41.     }
  42.  
  43.     server {
  44.         listen       80 default_server;
  45.         listen       [::]:80 default_server;
  46.         server_name  fdroidmirror.net;
  47.         root         /usr/share/nginx/html;
  48.         location /   {return 301 https://$server_name$uri;}
  49.         location /.well-known/ {default_type "text/plain";}
  50.     }
  51.  
  52.     server {
  53.         listen       443 ssl http2 default_server;
  54.         listen       [::]:443 ssl http2 default_server;
  55.         server_name  fdroidmirror.net;
  56.         root         /usr/share/nginx/html;
  57.  
  58.         ssl_certificate "/etc/acme/fdroidmirror.net/ec.crt";
  59.         ssl_certificate_key "/etc/acme/fdroidmirror.net/ec.key";
  60.         ssl_certificate "/etc/acme/fdroidmirror.net/rsa.crt";
  61.         ssl_certificate_key "/etc/acme/fdroidmirror.net/rsa.key";
  62.  
  63.     # https://www.nginx.com/blog/nginx-caching-guide/
  64.         ssl_session_cache shared:SSL:1m;
  65.         ssl_session_timeout  10m;
  66.  
  67.         ssl_ciphers "HIGH+kECDHE:-SSLv3:-SHA256:-SHA384:DES-CBC3-SHA:@STRENGTH";
  68.         ssl_prefer_server_ciphers on;
  69.     ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  70.     ssl_stapling on;
  71.     ssl_stapling_verify on;
  72.     ssl_early_data on;
  73.    
  74.         proxy_cache fdroid_cache;
  75.     # Cache key is just the uri, without any arguments
  76.     proxy_cache_key $uri;
  77.  
  78.     # Revalidation of expired cache items using conditional requests.
  79.     proxy_cache_revalidate on;
  80.  
  81.     # May use stale response    
  82.     #proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
  83.     proxy_cache_use_stale error timeout updating http_500 http_503;
  84.    
  85.     # Allows starting a background subrequest to update an expired cache item,
  86.     # while a stale cached response is returned to the client.     
  87.     proxy_cache_background_update on;
  88.        
  89.     # Only one request at a time to origin server per element
  90.     # Other request wait.
  91.     proxy_cache_lock on;
  92.     proxy_cache_lock_age 10s;
  93.     proxy_cache_lock_timeout 20s;
  94.        
  95.     proxy_cache_valid 200 302 10m;
  96.     proxy_cache_valid 301      1h;
  97.     proxy_cache_valid 404      5m;     
  98.     proxy_cache_valid any      1m;
  99.  
  100.     autoindex off;
  101.  
  102.     # Strip arguments from request to reduce possible attack vectors.
  103.     # We serve static content only, we do not want arguments.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement