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

  • Home
  • SEARCH
  • 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 6114857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:01:28+00:00 2026-05-23T15:01:28+00:00

I have a website(for example: test.com), which has 2 kinds of subdomains: test.com static_${version}.test.com

  • 0

I have a website(for example: test.com), which has 2 kinds of subdomains:

  1. test.com
  2. static_${version}.test.com

The 1st one is the main subdomain, and the 2nd one is only used for static files(js/css/image). The ${version} is a version number, it is changed when there is new version of js/css/images files, I need it because the client may cache the old ones.

Now I use nginx, but I don’t configure it about subdomains, just simply rewrite all subdomains to the main test.com domain.

It works, but one day I found a search engine, use the static.test.com as the main domain to visit my site.

How do I configure the nginx, to let the static.test.com can only visit static files, while the main domain can visit all?


UPDATE

I hope request of static.test.com with js/css/images will rewrite to test.com, not to a static file in disk. And other requests(not js/css/images) will return 404 directly.

Thanks for Timofey Stolbov’s answer, I write a config now:

server {
    listen 80;
    server_name ~^static_(.*)\.test\.com$;
    set $version $1;
    rewrite ^/public/(.*) http://test.com/public/$1?v=$version last;
    return 404;
}

Since my js/css/images files are all in “public” directory, so I just check if it starts with “public”. If not, just return 404.

But I don’t know is it correct, especially the return 404, or is there any better way to do this.

  • 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-05-23T15:01:29+00:00Added an answer on May 23, 2026 at 3:01 pm

    I use something like this.

    server {
      server_name static.test.com;
      root /var/www/static;
      location / {
        rewrite ^/([^\/]+\.css)$ /css/$1 break;
        rewrite ^/([^\/]+\.js)$ /js/$1 break;
        rewrite ^/([^\/]+\.(png|jpg|jpeg))$ /images/$1 break;
      }
    }
    

    For the second question

    Yes, your cofig is correct. But you should use permanent redirect or nginx will redirect request with 302 Moved Temporarily. Also listen 80 is implied by default.

    I don’t think that using redirect for every js/css/image is good idea, so think twice. 🙂

    And here is config.

    server {
        server_name ~^static_(.*)\.test\.com$;
        set $version $1;
        rewrite ^/public/(.*) http://test.com/public/$1?v=$version permanent;
        return 404;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a main folder in my website named test which contains
If I have 2 domain names that point to same website (for example: microsoft.com
I have two domains for example www.male.com and www.female.com which both point to the
I have a website, example.com hosted at godaddy. I was just messing around with
I have two websites, let's say they're example.com and anotherexample.net . On anotherexample.net/page.html ,
I have some website which requires a logon and shows sensitive information. The person
Say my URL address is www.example.com I want to have an if statement in
I have a Single Sign-on solution which is working great in our test environment.
I have a web site that is a customer to customer (C2C) service. Example,
I have a website that plays mp3s in a flash player. If a user

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.