nginx_conf.in 3.53 KB
Newer Older
1 2 3 4 5 6 7 8
worker_processes {{ param_nginx_frontend['nb_workers'] }};

pid {{ param_nginx_frontend['path_pid'] }};
error_log {{ param_nginx_frontend['path_error_log'] }};

daemon off;

events {
9 10
  worker_connections 1024;
  accept_mutex off;
11 12 13 14 15
}

http {
     default_type application/octet-stream;
     access_log {{ param_nginx_frontend['path_access_log'] }} combined;
16
     client_max_body_size 10M;
17 18 19 20
     map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
     }
21

22 23 24 25 26 27 28 29 30 31 32 33 34
     server {
        listen [{{ param_nginx_frontend['global-ip'] }}]:{{ param_nginx_frontend['global-port'] }} ssl;
        server_name _;
        ssl_certificate     {{ param_nginx_frontend['ssl-certificate'] }};
        ssl_certificate_key {{ param_nginx_frontend['ssl-key'] }};
        ssl_protocols       SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers         HIGH:!aNULL:!MD5;
        keepalive_timeout 90s;
        client_body_temp_path {{ param_tempdir['client_body_temp_path'] }};
        proxy_temp_path {{ param_tempdir['proxy_temp_path'] }};
        fastcgi_temp_path {{ param_tempdir['fastcgi_temp_path'] }};
        uwsgi_temp_path {{ param_tempdir['uwsgi_temp_path'] }};
        scgi_temp_path {{ param_tempdir['scgi_temp_path'] }};
35

36
        location / {
37 38
            # When no .htpasswd exist, redirect the user to account creation page
            if ( !-f {{ param_nginx_frontend['etc_dir'] }}/.htpasswd ) {
39 40 41 42 43 44 45 46 47 48 49
                # redirect URL is different wether nginx is accessed directly or behind apache.
                # nginx does not support nested if or multiple conditions, so we use this well known hack.
                set $test no_htpasswd;
            }
            if ( $host = [{{ param_nginx_frontend['global-ip'] }}] ) {
                set $test "${test}_backend_access";
            }
            if ( $test = no_htpasswd) {
                return 301 $scheme://$host/setAccount ;
            }
            if ( $test = no_htpasswd_backend_access) {
50 51
                return 301 /setAccount ;
            }
52
            auth_basic "Restricted";
53 54
            auth_basic_user_file {{ param_nginx_frontend['etc_dir'] }}/.htpasswd;
            proxy_redirect off;
55 56 57 58
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host  $http_host;
            proxy_set_header   X-Accel-Mapping   /private/;
59 60

            proxy_pass http://unix:{{ socket }};
61
        }
62
        location ~ ^(/login|/doLogin|/static|/setAccount|/configAccount|/slapgridResult|/isSRReady) {
63
            proxy_redirect off;
64 65 66 67
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host  $http_host;
            proxy_set_header   X-Accel-Mapping   /private/;
68 69

            proxy_pass http://unix:{{ socket }};
70
        }
71 72
        location /shellinabox {
            proxy_pass http://unix:{{ shellinabox_socket }}:/;
73
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
74
            auth_basic "Restricted";
75
            auth_basic_user_file {{ param_nginx_frontend['etc_dir'] }}/.htpasswd;
76 77 78
            proxy_redirect off;
            proxy_buffering off;
            proxy_set_header        X-Real-IP         $remote_addr;
79
            proxy_set_header        X-Forwarded-Proto $scheme;
80
            proxy_set_header        X-Forwarded-For   $proxy_add_x_forwarded_for;
81 82
            proxy_set_header        X-Forwarded-Host  $http_host;
      }
83
    }
84
}