about summary refs log tree commit diff
path: root/nanobox/nginx-web.conf.erb
blob: 182d9920993dcb5667e838e14f758f2254060cdc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
worker_processes 1;
daemon off;

events {
    worker_connections 1024;
}

http {
    include /data/etc/nginx/mime.types;
    sendfile on;

    gzip on;
    gzip_disable "MSIE [1-6]\.";
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_min_length 500;
    gzip_http_version 1.1;
    gzip_types text/plain text/xml text/javascript text/css text/comma-separated-values application/xml+rss application/xml application/x-javascript application/json application/javascript application/atom+xml;

    # Proxy upstream to the puma process
    upstream rails {
        server 127.0.0.1:3000;
    }

    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }

    # Configuration for Nginx
    server {
        # Listen on port 8080
        listen 8080;

        keepalive_timeout    70;
        client_max_body_size 80M;

        root /app/public;

        add_header Strict-Transport-Security "max-age=31536000";

        location / {
            try_files $uri @rails;
        }

        location /sw.js {
            add_header Cache-Control "public, max-age=0";
            add_header Strict-Transport-Security "max-age=31536000";
            try_files $uri @rails;
        }

        location ~ ^/(emoji|packs|system/media_attachments/files|system/accounts/avatars) {
            add_header Cache-Control "public, max-age=31536000, immutable";
            add_header Strict-Transport-Security "max-age=31536000";
            try_files $uri @rails;
        }

        # Proxy connections to rails
        location @rails {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto https;
            proxy_set_header Proxy "";
            proxy_pass_header Server;

            proxy_pass http://rails;
            proxy_buffering on;
            proxy_redirect off;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;

            proxy_cache CACHE;
            proxy_cache_valid 200 7d;
            proxy_cache_valid 410 24h;
            proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
            add_header Strict-Transport-Security "max-age=31536000";
            add_header X-Cached $upstream_cache_status;

            tcp_nodelay on;
        }
    }

    proxy_cache_path /data/var/cache/nginx levels=1:2 keys_zone=CACHE:10m inactive=7d max_size=1g;

    error_page 500 501 502 503 504 /500.html;
}