Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a server config like this

server {
    listen       80;
    server_name  www.site.com;
    server_name  stage.site.com;
    server_name  nagios.site.com;

    location ~* (.*)nagios {
        auth_basic "Admin";
        auth_basic_user_file /etc/nginx/.htpasswd;
    }

When I try to apply a location directive to the sub domain it does not seem to work.

I don’t want to duplicate server. It’s a lot of code.

How do I rectify this?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

When I try to apply a location directive to the sub domain it does not seem to work.

location directive is used for URI, not sub domain.

I don’t want to duplicate server. It’s a lot of code.

But it is the right way to do this. Checking $http_host with if directive is not recommend, either.

share|improve this answer
2  
You can put all the common bits into a separate file and include it in each server block to avoid copy/pasting. –  kolbyjack Sep 27 '11 at 12:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.