set nginx as proxy for both apache and gunicorn at the same time
Yes, this is possible. You'll need to configure Apache to listen on a different port though.
Don't select a reserved port and ensure that it's open (and that you can access it. Unix has a port range, usually defined in /proc/sys/net/ipv4/ip_local_port_range
if you chose ipv4, which you probably have judging by your Nginx config)
For Apache configuration:
Edit you apache main configuration file and set the Listen
directive as follows:
Listen 127.0.0.1:<port number that's open>
//Use 8080 as port for a start
Then create a VirtualHost as follows:
<VirtualHost 127.0.0.1:<port number defined above>> config goes here</VirtualHost>
You can do this in 2 ways, one from the same domain and one from a subdomain.
For NGINX configuration:
From the same domain:
server { listen 80; server_name XXXXX.com;#Django app served using Gunicorn location / { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_connect_timeout 120; proxy_read_timeout 120; proxy_pass http://localhost:8000/; }#PHP processed by Apache location ~ \.php$ { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_connect_timeout 120; proxy_read_timeout 120; proxy_pass http://localhost:<port you configured apache to listen on>/; }}
From a subdomain:
#Server block for Django server { listen 80; server_name XXXXX.com; location / { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_connect_timeout 120; proxy_read_timeout 120; proxy_pass http://localhost:8000/; }}#Server block for PHP served using Apache with a subdomainserver { listen 80; server_name blog.XXXXX.com; location / { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_connect_timeout 120; proxy_read_timeout 120; proxy_pass http://localhost:<port you configured apache to listen on>/; }}
Note: You don't need the root directive because your applications are being served by either Gunicorn or being handed over to Apache (where you'll define a root in the VirtualHost)
Once you've edited your config files, restart Apache and then restart Nginx, it should work.