krarve
By:
krarve

Problems setting up an nginx server

May 2, 2016 606 views
DNS Nginx Django DigitalOcean Ubuntu

I have successfully set up an nginx server with django with the following settings:

Settings at domain registrar:

Digital Oceans DNS nameservers

Nginx settings:

    server {
        server_name www.izubehoer.ch;
        return 301 $scheme://izubehoer.ch$request_uri;
    }

    server {
        server_name izubehoer.ch;

        access_log off;

        location /static/ {
            alias /home/wt_konsulat_env/static/;
        }

        location / {
                proxy_pass http://127.0.0.1:8000/;
                proxy_set_header X-Forwarded-Host $server_name;
                proxy_set_header X-Real-IP $remote_addr;
                add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
        }
    }

Now I want to do the same thing with another domain (se-konsulat.ch), but this time I can't change the DNS settings at the domain registrar as the domain is hosted with someone else and the email server should not run via DO. That's why only a DNS A record is placed (for http://se-konsulat.ch) pointing to the ip of my DO server.
When I leave the nginx settings unchanged, accessing se-konsulat.ch redirects me to izubehoer.ch, which I assume is the correct behavior.

*But what I want is to only have se-konsulat.ch (I only used izubehoer.ch for testing purposes). So when accessing se-konsulat.ch I don't want it to redirect to izubehoer.ch, I want it to show the django website as se-konsulat.ch.
*

I have tried various settings without success. I am new to nginx and would appreciate any help you can give me!

2 comments
  • Where is the django site you want to be displayed for se-konsulat.ch? Is it on this droplet, on another server, etc?

  • it is on that droplet

1 Answer

Hi @krarve,

If I'm understanding you correctly you'd like to run a different application for se-konsulat.ch than izubehoer.ch, and you'd like to simply have NGINX direct the inbound connections to each of the django applications. If so, you could do this with server blocks within NGINX as described here: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-14-04-lts.

If this is not the case, and you'd like the same application to display different templates/content for each of the websites, and do all of this within django, that's probably going to be a lot more work than simply running two copies of the django application (which I'd suggest doing instead).

Let me know if you have any further questions! and if this doesn't get you sorted, please let us know!

Have another answer? Share your knowledge.