[Answer]-Django apps on nginx running separately from apache

0๐Ÿ‘

โœ…

1. How do you set it up with domain name?
In the server block of your nginx conf file set the server_name:

    server {
        listen 8000;
        server_name www.my-django-domain-one.foobar;
        #rest of your config regarding forwarding to django...
    }

Your site will be available at http://www.my-django-domain-one.foobar:8000.

2. How do you add another domain name? (new app)
Nginx will not decide anything based on the conf filename. Create a new conf file or use the existing one (only matters in the sense of how you want to organize your configs)

    server {
        listen 8000;
        server_name www.my-django-domain-two.foobar;
        #rest of your config regarding forwarding to django...
    }

However, I recommend an approach involving only one web server. Opinions on which to use vary of course but both of them can do what you want to achieve on their own. You add unnecessary complexity to your setup (e.g. two servers to keep patched) and -depending on your traffic- it may even have a significant impact on your performance.

Check out this tutorial to see how you could make your php apps work with nginx and php-fpm.

๐Ÿ‘คmazerraxuz

1๐Ÿ‘

Thanks for your answer. To make it work I had to set apache proxy like this:

<VirtualHost *:80>
  ServerName www.domain.com

  ProxyPreserveHost On

  ProxyPass /static http://XX.XX.XX.XX:8000/static
  ProxyPassReverse /static http://XX.XX.XX.XX:8000/static


  ProxyPass / http://XX.XX.XX.XX:8000
  ProxyPassReverse / http://XX.XX.XX.XX:8000

  RewriteEngine On

  RewriteCond %{REQUEST_URI} ^(.(?!\.css|js|gif|png|jpg|ico))*$
  RewriteRule /(.*) http://XX.XX.XX.XX:8000/$1 [P,L]
</VirtualHost>

and enable proxy_http:

sudo a2enmod proxy  
sudo a2enmod proxy_http  
sudo service apache2 restart
๐Ÿ‘คLucas03

Leave a comment