gliders.nginx.conf 3.39 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65
    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;
    }

66
    error_page 413 /413.html;
Owain Jones's avatar
Owain Jones committed
67
    error_page 502 /502.html;
68
    error_page 504 /504.html;
69 70 71 72 73
    error_page 503 @maintenance;
    location @maintenance {
        rewrite ^(.*)$ /maintenance.html break;
    }

root's avatar
root committed
74 75 76 77 78 79 80 81 82 83 84 85
    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;
    }

86 87 88 89
    location /var/gliders/logs {
        alias /var/gliders/logs;
    }

90 91
    location /static {
        alias /var/gliders/static;
root's avatar
root committed
92 93
    }

Owain Jones's avatar
Owain Jones committed
94 95 96 97 98 99
    location /static/images {
        access_log off;
        error_log off;
        alias /var/gliders/static/images;
    }

root's avatar
root committed
100
    location @rewriteapp {
101
        rewrite ^(.*)$ /${symfonyfile}.php/$1 last;
root's avatar
root committed
102 103 104 105
    }

    # pass the PHP scripts to FastCGI server from upstream phpfcgi
    location ~ ^/(app|app_dev|config)\.php(/|$) {
106 107
        # fastcgi_pass hhvmfcgi;
        fastcgi_pass phpfcgi;
108
        fastcgi_intercept_errors on;
109 110
        # error_page 502 = @fallback;
        error_page 502 /502.html;
root's avatar
root committed
111 112
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
113
        fastcgi_param  SCRIPT_FILENAME $symfonyroot/web$fastcgi_script_name;
root's avatar
root committed
114 115
        fastcgi_param  HTTPS off;
    }
116

117 118 119 120 121 122 123 124 125
    # 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
126
}