1

I´ve got an NGINX docker container which receives requests at port 8089 (Reverse proxied by an NGINX on my main system). It should then retrieve the $host variable to determine the correct root directory to serve. In my error log, NGINX is complaining about "Root directive not allowed here".
How can I achieve the same without any errors?
Here´s my NGINX config file:

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        server_name _;
        set $handle 0;
        if ($host = 'lsg.example.com') {
                set $handle 2;
        }
        if ($host = 'www.example.com') {
                set $handle 1;
        }
        if ($handle = 0) {
                return 501;
        }
        if ($handle = 1) {
                root /var/www/laravel/public; #root directive not allowed here
                index index.php index.html index.htm;
        }
        if ($handle = 2) {
                root /var/www/pizza/public;
                index index.php index.html index.htm;
        }
        # Laravel params:
        location / {
                try_files $uri $uri/ /index.php$is_args$args;
        }
        location ~ \.php$ {
                try_files $uri /index.php =404;
                fastcgi_pass php-upstream;
                fastcgi_index index.php;
                fastcgi_buffers 16 16k;
                fastcgi_buffer_size 32k;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                #fixes timeouts
                fastcgi_read_timeout 600;
                include fastcgi_params;
        }
        location ~ /\.ht {
                deny all;
        }
        location /.well-known/acme-challenge/ {
                root /var/www/letsencrypt/;
                log_not_found off;
        }
        error_log /var/log/nginx/laravel_error.log;
        access_log /var/log/nginx/laravel_access.log;
}
1
  • This should be 3 separate server blocks without ifs
    – Alexey Ten
    Mar 17, 2019 at 16:26

2 Answers 2

0

Seems like your server do not have connection with docker container operated on same host. In your example you have upstream laradock, which serving requests to 127.0.0.1:8089.

Be sure your docker container exposing this port and you can make a successful request to it from the host where your web server is running:

curl http://127.0.0.1:8089
1
  • Oh, I see now. My logs for the docker container complain of me not allowed to set a root directory in a if-clause. I will shortly edit my question to fit with my real problem.
    – 3x071c
    Mar 16, 2019 at 20:28
0

Turns out I can just use the server_name directive to differentiate between different $host variables. Thanks for any help anyway!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .