Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7716493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:39:08+00:00 2026-06-01T02:39:08+00:00

I have nginx acting as a reverse proxy to apache. I now need to

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:39:09+00:00Added an answer on June 1, 2026 at 2:39 am

    You could move the common parts to another configuration file and include from both server contexts. This should work:

    server {
      listen 80;
      server_name server1.example;
      ...
      include /etc/nginx/include.d/your-common-stuff.conf;
    }
    
    server {
      listen 80;
      server_name another-one.example;
      ...
      include /etc/nginx/include.d/your-common-stuff.conf;
    }
    

    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 server bunkus.org‘s configuration file is /etc/nginx/sites-enabled and it looks like this:

    server {
      listen   80 default_server;
      listen   [2a01:4f8:120:3105::101:1]:80 default_server;
    
      include /etc/nginx/include.d/all-common;
      include /etc/nginx/include.d/bunkus.org-common;
      include /etc/nginx/include.d/bunkus.org-80;
    }
    
    server {
      listen   443 default_server;
      listen   [2a01:4f8:120:3105::101:1]:443 default_server;
    
      include /etc/nginx/include.d/all-common;
      include /etc/nginx/include.d/ssl-common;
      include /etc/nginx/include.d/bunkus.org-common;
      include /etc/nginx/include.d/bunkus.org-443;
    }
    

    As an example here’s the /etc/nginx/include.d/all-common file that’s included from both server contexts:

    index index.html index.htm index.php .dirindex.php;
    try_files $uri $uri/ =404;
    
    location ~ /\.ht {
      deny all;
    }
    
    location = /favicon.ico {
      log_not_found off;
      access_log off;
    }
    
    location ~ /(README|ChangeLog)$ {
      types { }
      default_type text/plain;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have nginx setup, acting as a reverse proxy to apache. However, I need
Now that I have nginx setup I need to be able to hide my
I have a website set up with nginx acting as a reverse proxy to
I have nginx reverse proxying to apache and if I add Deny from 111.111.111.111
I have a rails application running on Nginx which needs to serve files for
I have an NGINX server with fastcgi/PHP running on it. I need to add
I heard recently that Nginx has added caching to its reverse proxy feature. I
I have two websites running on my own root server (ubuntu/nginx/php-fpm). Now I want
I have a rewrite that nginx calls like so: location ~* (css)$ { rewrite
I have the nginx upload module handling site uploads, but still need to transfer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.