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;
}