gliders.nginx.conf 3.71 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

root's avatar
root committed
38
    location / {
39
    	limit_req zone=gliders burst=5;
40
        set $index_file $symfonyfile".php";
41 42 43 44
     	if (-f $document_root/.maintenance) {
            return 503;
        }
        index $index_file;
root's avatar
root committed
45 46 47
        try_files $uri @rewriteapp;
    }

48 49 50 51
    location /dashboard.php {
        return 301 /dashboard;
    }

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    location /mission.php {
        return 301 /missions;
    }

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

    location /glider {
        return 301 /;
    }

    location /favicon.ico {
        return 404;
        access_log off;
        error_log off;
    }

70
    error_page 413 /413.html;
Owain Jones's avatar
Owain Jones committed
71
    error_page 502 /502.html;
72
    error_page 504 /504.html;
73 74 75 76 77
    error_page 503 @maintenance;
    location @maintenance {
        rewrite ^(.*)$ /maintenance.html break;
    }

root's avatar
root committed
78 79 80 81 82 83 84 85 86 87 88 89
    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;
    }

90 91 92 93
    location /var/gliders/logs {
        alias /var/gliders/logs;
    }

94 95
    location /static {
        alias /var/gliders/static;
root's avatar
root committed
96 97
    }

98 99 100 101 102
    location /static/tracks {
        alias /var/gliders/static/tracks;
        gzip_static on;
    }

Owain Jones's avatar
Owain Jones committed
103 104 105 106 107 108
    location /static/images {
        access_log off;
        error_log off;
        alias /var/gliders/static/images;
    }

root's avatar
root committed
109
    location @rewriteapp {
110
        rewrite ^(.*)$ /${symfonyfile}.php/$1 last;
root's avatar
root committed
111 112
    }

113 114 115 116 117
    # location /realtime {
    #     proxy_pass http://localhost:9002/;
    #     proxy_read_timeout 10m;
    #     proxy_connect_timeout 10m;
    # }
Owain Jones's avatar
Owain Jones committed
118

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

132 133 134 135 136 137 138 139 140
    # 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
141
}