I have a Ubuntu server running Apache, which hosts a Wordpress site, which is accessible using HTTP. There's also Nginx installed that hosts a Django site that's only accessible using HTTPS.
Now, what I'd like to accomplish is that example.com and www.example.com would go to the Wordpress hosted by Apache, while api.example.com would go to the Django hosted by Nginx. This does work at the moment if I just try to access the main page at api.example.com, but there's one weird catch: When I try to access api.example.com/admin (Django admin panel), the page gets redirected to the Wordpress admin login page at www.example.com/wp-admin. Why is that?
I've even tried to change the Django admin panel URL to something else. This in turns leads to Wordpress 404 page ("Oops, that page could not be found!").
So, it seems that the portion of the URL after the domain gets hijacked by Apache, even though it's on the different subdomain. What causes this, and how can I fix it?
The Apache site is configured like this:
<VirtualHost *:80> ServerName www.example.com DocumentRoot /var/www/wp <Directory /var/www/wp> Options Indexes FollowSymlinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> </VirtualHost> And the Nginx site is configured like so:
upstream app_server { server unix:/tmp/gunicorn.sock fail_timeout=0; } server { listen 443 ssl; charset utf-8; server_name api.example.com; ssl on; # Here be a lot of SSL configs location / { try_files $uri @proxy_to_app; } location @proxy_to_app { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_pass http://app_server; } location /static { root /var/www/django/static; } } Finally, my DNS record is set up like this:
A example.com 1.2.3.4 CNAME api example.com CNAME www example.com Thanks for your help in advance. Let me know if you need more information.