I have a question regarding the proxy_pass and dynamic subdomains.
on my server, I have a site_block which looks like this:
#############################################
upstream mydockersite{
server 127.0.0.1:8081;
}
server {
listen 80;
server_name ~^review-+(?<subdomain>.+)\.website\.com;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
proxy_pass http://mydockersite;
}
}
###################################################
Which works fine with redirecting incoming requests, made to my server to my docker container which is also a NGINX server.
For example:
http://review-xyz.website.com
Or
http://review-somedynamicsubdomain.website.com
Or
http://review-anothersubdomain.website.com
Where the review- portion is fixed the <subdomain> portion could be anything and website.com is my domain anyway.
I see that the whole request domain can be passed to the server in my docker container with the header that I set proxy_set_header Host $host; but I have no idea how to grab them in the config of my docker nginx server and redirect to the requested root folder.
The configuration of the nginx server which is in my docker container looks like this:
###########################################################3
server {
listen 80;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
######## MY PROBLEM IS HERE ########
root /home/site_reviews/main;
####################################
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}
############################################
At the line: root /home/site_reviews/main; I need to replace the main portion with the <subdomain> portion of the proxy_pass
So the root folder where the website is being served from will be the subdomain
For example if I have an URL like this: review-x34kk4ids.website.com, then my docker container nginx should serve the folder x34kk4ids which is in the docker folder /home/site_reviews/