Saturday, September 2, 2017

Two Nginx subdomains with different root folders but both going to the same?

I'm trying to figure out why a subdomain I just created in Nginx isn't using the root folder specified in it's configuration file. Below is the config file for the subdomain zeta.




server {
listen 80;

root /var/www/zeta;
server_name zeto.mydomain.com;
error_log /var/log/nginx/subdomains_error.log;
error_page 404 /404.html;
if ($subdomain = ""){
set $subdomain something;
rewrite /.* /not_found;

}
location / {
index index.php index.html index.htm;
access_log /var/log/nginx/subdomains_access.log;
location / {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
access_log /var/log/nginx/subdomains_php_access.log;


}
location /public {
}
location ~ \.(js|ico|gif|jpg|png|css)$ {
}
location /not_found {
}
location /404.html {
internal;

}
}

}


I have another domain file which is setup to with a wildcard subdomain and different root folder see below it's the only difference



root /var/www/account;
server_name *.mydomain.com;



There's a text file in /etc/nginx called subdomains. A perl file reads the list of subdomains and if one exists it loads the page otherwise shows an error. I know that my wildcard subdomain file is picking up zeta as it's in the subdomains text file. It's setup like this because the server is an application and when visitors register we add their chosen subdomain to the file and reload Nginx without affecting users already on the site.



What changes can I make to the zeta file so that it'll use /var/www/zeta as the root folder and not the root folder in the wildcard config file?



Thanks

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...