gliders.nginx.conf 4.05 KB
Newer Older
Owain Jones's avatar
Owain Jones committed
1 2 3
# https://www.nginx.com/resources/wiki/start/topics/recipes/symfony/
# NOTE: This makes any .php file other than app, app_dev and config.php
# downloadable. If you want one to run, add it to the "pass the PHP scripts to
root's avatar
root committed
4
# upstream FCGI" location section below. Be careful adding files with
Owain Jones's avatar
Owain Jones committed
5 6
# sensitive data like passwords inside them.

7 8
limit_req_zone $binary_remote_addr zone=gliders:10m rate=10r/s;

9 10
server {
    listen 80;
root's avatar
root committed
11

12
    server_name ~(?:((?<symfonyenv>.+)\.)?gliders.*|mars\.noc\.ac\.uk);
Owain Jones's avatar
Owain Jones committed
13

14 15 16 17
    if ($symfonyenv) {
        set $symfonyfile "app_$symfonyenv";
        set $symfonyroot "/var/gliders/www_$symfonyenv";
    }
18

19 20 21 22 23
    if ($symfonyenv = "") {
        set $symfonyfile "app";
        set $symfonyroot "/var/gliders/www";
        set $symfonyenv "prod";
    }
root's avatar
root committed
24

25
    root $symfonyroot/web;
root's avatar
root committed
26

Owain Jones's avatar
Owain Jones committed
27
    error_log /var/log/nginx/gliders.error.log;
28
    access_log /var/log/nginx/$symfonyenv.gliders.access.log;
root's avatar
root committed
29

root's avatar
root committed
30 31 32
    # Enable compression. Very helpful when we're getting stuff like
    # large amounts of vehicle tracks in JSON form!
    gzip on;
33
    gzip_types text/plain application/xml text/html text/css application/json application/x-javascript text/xml text/javascript application/javascript;
root's avatar
root committed
34

Owain Jones's avatar
Owain Jones committed
35
    # strip app.php/ prefix if it is present
36
    rewrite ^/$symfonyfile\.php/?(.*)$ /$1 permanent;
Owain Jones's avatar
Owain Jones committed
37

38 39 40 41 42 43 44 45 46
    location @ppm {
        proxy_set_header Host $http_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 $scheme;
        proxy_pass http://127.0.0.1:8005;
        error_page 502 /502.html;
    }

root's avatar
root committed
47
    location / {
48
    	limit_req zone=gliders burst=5;
49
        set $index_file $symfonyfile".php";
50 51 52 53
     	if (-f $document_root/.maintenance) {
            return 503;
        }
        index $index_file;
54 55
        # try_files $uri @rewriteapp;
        try_files $uri @ppm;
root's avatar
root committed
56 57
    }

58 59 60 61
    location /dashboard.php {
        return 301 /dashboard;
    }

62 63 64 65 66 67 68 69 70 71 72 73
    location /mission.php {
        return 301 /missions;
    }

    location /glider/mission.php {
        return 301 /missions;
    }

    location /glider {
        return 301 /;
    }

74
    error_page 413 /413.html;
Owain Jones's avatar
Owain Jones committed
75
    error_page 502 /502.html;
76
    error_page 504 /504.html;
77 78 79 80 81
    error_page 503 @maintenance;
    location @maintenance {
        rewrite ^(.*)$ /maintenance.html break;
    }

root's avatar
root committed
82 83 84 85 86 87 88 89 90 91 92 93
    location ~ ^/(images|fonts|css|js) {
        access_log off;
        error_log off;
        try_files $uri =404;
        expires 1y;
        add_header Cache-Control "public";
    }

    location /static/logs {
        alias /var/gliders/logs;
    }

94 95 96 97
    location /var/gliders/logs {
        alias /var/gliders/logs;
    }

98 99
    location /static {
        alias /var/gliders/static;
root's avatar
root committed
100 101
    }

102 103 104 105 106
    location /static/tracks {
        alias /var/gliders/static/tracks;
        gzip_static on;
    }

Owain Jones's avatar
Owain Jones committed
107 108 109 110 111 112
    location /static/images {
        access_log off;
        error_log off;
        alias /var/gliders/static/images;
    }

root's avatar
root committed
113
    location @rewriteapp {
114
        rewrite ^(.*)$ /${symfonyfile}.php/$1 last;
root's avatar
root committed
115 116
    }

117 118 119 120 121
    # location /realtime {
    #     proxy_pass http://localhost:9002/;
    #     proxy_read_timeout 10m;
    #     proxy_connect_timeout 10m;
    # }
Owain Jones's avatar
Owain Jones committed
122

root's avatar
root committed
123
    # pass the PHP scripts to FastCGI server from upstream phpfcgi
124 125
    # location ~ ^/(app|app_dev|config)\.php(/|$) {
    location @fpm {
126 127
        # fastcgi_pass hhvmfcgi;
        fastcgi_pass phpfcgi;
128
        fastcgi_intercept_errors on;
129 130
        # error_page 502 = @fallback;
        error_page 502 /502.html;
root's avatar
root committed
131 132
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
133
        fastcgi_param  SCRIPT_FILENAME $symfonyroot/web$fastcgi_script_name;
root's avatar
root committed
134 135
        fastcgi_param  HTTPS off;
    }
136

137 138 139 140
    location ~ ^/(app|app_dev|config)\.php(/|$) {
        try_files $uri @fpm;
    }

141 142 143 144 145 146 147 148 149
    # location @fallback {
    #     fastcgi_pass phpfcgi;
    #    fastcgi_intercept_errors on;
    #    include fastcgi_params;
    #    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    #    fastcgi_param SCRIPT_FILENAME $symfonyroot/web$fastcgi_script_name;
    #    fastcgi_param HTTPS off;
    #    error_page 502 /502.html;
    #}
root's avatar
root committed
150
}