Article 5587N Config problems - NGINX reverse proxy to Apache server for multiple subdomains

Config problems - NGINX reverse proxy to Apache server for multiple subdomains

by
orrin5250
from LinuxQuestions.org on (#5587N)
I will admit right off the bat I seem to be in over my head. I am a simple hobbyist.

I am trying to set up a website with multiple subdomains:

example.com
blog.example.com
cloud.example.com

I have Debain 10 installed on a VPS (Kamatera) and using *just* apache, I can browse each url and view a unique html page.

I then tried to set up nginx as a reverse proxy and despite scouring the net for days and making at least 10 different attempts...no luck. I seem to be missing something fundamental.

I believe DNS settings are correct (like I said, with apache alone, it's working):
Type Name Value
A @ 1.2.3.4 (of course not really)
A blog 1.2.3.4
A cloud 1.2.3.4

I have this added to apache2.conf file:
Code:NameVirtualHost 1.2.3.4:8080

<VirtualHost 1.2.3.4>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost 1.2.3.4>
ServerName blog.example.com
DocumentRoot /var/www/html/blog
</VirtualHost>

<VirtualHost 1.2.3.4>
ServerName cloud.exmaple.com
DocumentRoot /var/www/html/cloud
</VirtualHost>I have set /etc/apache2/port.conf to:
Listen 127.0.0.1:8080

These are my nginx.conf entries:
Code: server {
listen 80;
server_name example.com;
location / {
root /var/www/html;
proxy_pass http://127.0.0.1:8080/;
proxy_redirect http://127.0.0.1:8080/ http://example.com/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;

}
}

server {
listen 80;
server_name blog.example.com;
location / {
root /var/www/html/blog;
proxy_pass http://127.0.0.1:8080/;
proxy_redirect http://127.0.0.1:8080/ http://blog.example.com/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;

}
}

server {
listen 80;
server_name cloud.example.com;
location / {
root /var/www/html/cloud;
proxy_pass http://127.0.0.1:8080/;
proxy_redirect http://127.0.0.1:8080/ http://cloud.example.com/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;

}
}The trouble I am having is that browsing subdomains defaults to the home page html in /var/www/html. I have not successfully configured nginx so that I can browse the subdomains.

Ports:
Code:orrin@orrin-cloud:~/old-nginx-attempt/nginx$ sudo netstat -anp | grep apache
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 26156/apache2
orrin@orrin-cloud:~/old-nginx-attempt/nginx$ sudo netstat -anp | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 26458/nginx: master
unix 3 [ ] STREAM CONNECTED 226198 26458/nginx: master
unix 3 [ ] STREAM CONNECTED 226197 26458/nginx: masterAny ideas? I am wondering if this is because there is nothing in my sites-available/enabled directories except default settings? Strangely enough with apache alone that somehow works.latest?d=yIl2AUoC8zA latest?i=dMqR_-yfK-A:mVa6KXTsjE8:F7zBnMy latest?i=dMqR_-yfK-A:mVa6KXTsjE8:V_sGLiP latest?d=qj6IDK7rITs latest?i=dMqR_-yfK-A:mVa6KXTsjE8:gIN9vFwdMqR_-yfK-A
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments