I have nginx acting as a reverse proxy to apache. I now need to add a new subdomain
that will serve files from another directory, but at the same time I want all location and proxy_pass directives that I have for the default host to apply to the subdomain also.
I know that if I copy the rules from the default host to the new subdomain it will work, but is there a way for the subdomain to inherit the rules?
Below is a sample configuration
server {
listen 80;
server_name www.somesite.com;
access_log logs/access.log;
error_log logs/error.log error;
location /mvc {
proxy_pass http://localhost:8080/mvc;
}
location /assets {
alias /var/www/html/assets;
expires max;
}
... a lot more locations
}
server {
listen 80;
server_name subdomain.somesite.com;
location / {
root /var/www/some_dir;
index index.html index.htm;
}
}
Thanks
You could move the common parts to another configuration file and
includefrom both server contexts. This should work:Edit: Here’s an example that’s actually copied from my running server. I configure my basic server settings in
/etc/nginx/sites-enabled(normal stuff for nginx on Ubuntu/Debian). For example, my main serverbunkus.org‘s configuration file is/etc/nginx/sites-enabledand it looks like this:As an example here’s the
/etc/nginx/include.d/all-commonfile that’s included from bothservercontexts: