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'm running a configuration on Plesk during which Plesk randomly overwrites my nginx.conf with a default template, so what I'm trying to do is change the template by including another configuration file if needed(something like how httpd.conf and vhost.conf) works, but the question is, would it work if i repeated the same tags, for example I have this nginx configuration:

server {
    listen 72.25.454.19:80;

    server_name example.com;
    server_name www.example.com;
    server_name ipv4.example.com;


    client_max_body_size 128m;

    location / { # IPv6 isn't supported in proxy_pass yet.
        proxy_pass http://72.55.164.89:7080;

        proxy_set_header Host             $host;
        proxy_set_header X-Real-IP        $remote_addr;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header X-Accel-Internal /internal-nginx-static-location;
        access_log off;
    }

    location /internal-nginx-static-location/ {
        alias      /usr/share/tomcat6/psa-webapps/example.com/example/;
        access_log /var/www/vhosts/example.com/statistics/logs/proxy_access_log;
        add_header X-Powered-By PleskLin;
        internal;
    }
}

and I added the same declaration only to change the alias, would nginx merge the two configurations, or just take the last one, not sure how it works.

server {
    listen 72.25.454.19:80;

    location /internal-nginx-static-location/ {
        alias      /usr/share/tomcat6/psa-webapps/example.com/example2/;
    }
}
share|improve this question
    
why add server block for just adding an alias? you could use include directive inside location /internal-nginx-static-location/ and there will be configuration file managed by Plesk with all necessary aliases. –  Andrei Mikhaltsov May 8 '13 at 14:45
    
@AndreiMikhaltsov yea but if i did so, ill have duplicate alias if i added another alias in the configuration file, can i just override the location directive with another one in the configuration file –  Yehia A.Salam May 8 '13 at 16:32

1 Answer 1

What you did is not the same server block without the server_name.

I would say that the 2nd config *without server_name* will be considered as default config. Then overruled by the 1st config *with server_name*.

There is also no redeclare location. For example...

root@ubuntu:/etc/nginx/sites-enabled# cat a
server {
    listen 80;
    server_name 192.168.2.104;
    client_max_body_size 128m;

    location /internal-nginx-static-location/ {
        alias      /tmp/a/;
    }

    location /internal-nginx-static-location/ {
        alias      /tmp/c/;
    }
}
root@ubuntu:/etc/nginx/sites-enabled# nginx -t
nginx: [emerg] duplicate location "/internal-nginx-static-location/" in /etc/nginx/sites-enabled/a:10
nginx: configuration file /etc/nginx/nginx.conf test failed

I hope that helps.

share|improve this answer

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.