HHH
By:
HHH

[emerg] duplicate upstream "app_server" in /etc/nginx/sites-enabled/<project_name>:1

January 22, 2015 10.7k views

I'm following this tutorial by @asb.
But i got this error when I try restart nginx:

[emerg] duplicate upstream "app_server" in /etc/nginx/sites-enabled/test-django:1

The test-django file in etc/nginx/site-available/ :

upstream app_server {
    server 127.0.0.1:9500 fail_timeout=0;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.html index.htm;

    client_max_body_size 4G;
    server_name www.mydomain.com;

    keepalive_timeout 5;

    # Your Django project's media files - amend as required
    location /media  {
        alias /home/django/test-django/cmsh/media;
    }

    # your Django project's static files - amend as required
    location /static {
        alias /home/django/test-django/cmsh/static;
    }

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app_server;
    }
}
1 Answer

Never mind this fix the error:

cd  /etc/nginx/sites-enabled/

sudo rm -r test-django

sudo service nginx restart

 * Restarting nginx nginx    

and my test-django looks like this now:

upstream app_server {
    server 127.0.0.1:9500 fail_timeout=0;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.html index.htm;

    client_max_body_size 4G;
    server_name www.mydomain.com;

    keepalive_timeout 5;

    # Your Django project's media files - amend as required
    location /media  {
        alias /home/django/test-django/cmsh/media;
    }

    # your Django project's static files - amend as required
    location /static {
        alias /home/django/test-django/cmsh/static;
    }

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app_server;
    }
}

'default_server' were deleted

source

  • but why everytime I enter in browser my newsite.com it opens oldsite.com?

  • server_name should include both www.domain.com and domain.com:

    server_name www.mydomain.com mydomain.com;
    

    Update the server blocks so that server_name is set properly. Only one server block should have default_server, which is the server block that you want nginx to serve when it gets a request to a domain name that it does not know about.

    Make sure you restart nginx after making any changes to the configuration files:

    sudo service nginx restart
    
  • Iit still redirect me to the first site. Deleted default_server, add www.mydomain.com and mydomain.com

    I created my VPS with Django one-click install on Ubuntu, but I didn't make any virtualenv. Maybe this is the problem? Or my DNS configuration is wrong?

Have another answer? Share your knowledge.