LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-16-2022, 03:41 AM   #1
Umeraf
LQ Newbie
 
Registered: Nov 2018
Posts: 26

Rep: Reputation: Disabled
Ubuntu server with three different services


I have ubuntu server 20.04 in which three different sites running one on django and one wordpress and ohter on nodejs three different domain name is dedicted for this for example

abc.com running on django
xyz.com on Apache(wordpress site)
efg.com on nodjs

and these domain are register with hostinger and also use there nameserver

and there A record already enter in hostinger name servers
abc.com A 10.10.10.10
xyz.com A 10.10.10.10
efg.com A 10.10.10.10

Now how i manage these three on same server to listen all on port 80
for example when client open abc.com in browser it shows django site and when client open xyz.com its open wordpress site and similar when client open efg.com in browser its open nodejs site so how i achieve this on ubuntu 20.04 server
 
Old 08-16-2022, 09:49 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,168
Blog Entries: 1

Rep: Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038
Quote:
Now how i manage these three on same server to listen all on port 80
for example when client open abc.com in browser it shows django site and when client open xyz.com its open wordpress site and similar when client open efg.com in browser its open nodejs site so how i achieve this on ubuntu 20.04 server
What you need is a reverse proxy in front of these 3 services. You can either use apache or nginx for this.
There are lots of howtos on the net about configuring an apache or nginx reverse proxy on ubuntu. Follow one of those and post here if you have a specific problem

Regards
 
2 members found this post helpful.
Old 08-16-2022, 10:39 AM   #3
elgrandeperro
Member
 
Registered: Apr 2021
Posts: 415
Blog Entries: 2

Rep: Reputation: Disabled
You can use named based virtual hosting. Name base Virtual hosting depends on the URL (what the browser is typed) and satisfies the request dependent on that.

There is IP based Virtual hosting, but then you would need to bind 2 extra ips to your box and then change the DNS entry for 2 of your instances.

You will have to separate all the site specific things into the VirtualHost areas, this is usually not a problem.

https://httpd.apache.org/docs/2.4/vh...ame-based.html
 
2 members found this post helpful.
Old 08-17-2022, 08:22 PM   #4
Umeraf
LQ Newbie
 
Registered: Nov 2018
Posts: 26

Original Poster
Rep: Reputation: Disabled
Thankyou @bathory for your reply I follow apache2 as a reverse proxy and below is my virtual host settings
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ProxyVia Full

<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://abc.com:80/
ProxyPassReverse / http://abc.com:80/

ServerName abc.com

</VirtualHost>

Above is my Django app settings

<VirtualHost *:3000>
ProxyPreserveHost On
ProxyRequests Off
ProxyVia Full

<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://xyz.com:3000/
ProxyPassReverse / http://xyz.com:3000/

ServerName xyz.com

</VirtualHost>

above is my nodejs setting

<VirtualHost *:8080>

ProxyPreserveHost On
ProxyRequests Off
ProxyVia Full

<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://efg.com:8080/
ProxyPassReverse / http://efg.com:8080/
ServerName efg.com
ServerAdmin webmaster@localhost

DocumentRoot /var/www/html/efg.com
<Directory /var/www/html/efg.com>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>
above is WordPress site setting
problem is that all the above domains' names open the same page of abc.com not show the nodjs and WordPress site.

need help in this.

Last edited by Umeraf; 08-17-2022 at 08:29 PM.
 
Old 08-17-2022, 10:30 PM   #5
elgrandeperro
Member
 
Registered: Apr 2021
Posts: 415
Blog Entries: 2

Rep: Reputation: Disabled
You are mixing the proxy and virtual hosting. You only want externally port 80 for inbound and use server name to route to the virtualhost instance. You want all proxy configs IN the virtual host. You don't need to proxy wordpress because it runs
in apache. The first config is default. I usually put a VH that returns 404 for the first one, because no one should use the ip or a name you don't know about but that can be done later.

Each virtualhost stands alone, the proxy directive (even if repeated) should only be in each virtualhost. Define separate log files for each virtualhost (access/error) so you know which one is being accessed.

So the first virtualhost which in your config is django. It looks like your want port 80 to 80, I would unbind localhost from apache and that way you can use http://localhost:80

<VirtualHost *:80>
ServerName abc.com

Your Django config, proxy forward to localhost 80.

</VirtualHost>

<VirtualHost *:80>
Servername xyz.com

wordpress config (you don't need to proxy it, it is "native" apache.
</VirtualHost>

<VirtualHost *:80>
Servername efg.com

PROXY STUFF For nodejs forward port 8080 ( you can use localhost 8080 if you redo the bind)
</VirtualHost>

BTW, I haven't used proxy directives for a long time, but I have had a apache server with multiple sites AND a proxy so I know it can be done...

Last edited by elgrandeperro; 08-17-2022 at 10:32 PM. Reason: added...
 
Old 08-17-2022, 11:01 PM   #6
Umeraf
LQ Newbie
 
Registered: Nov 2018
Posts: 26

Original Poster
Rep: Reputation: Disabled
Thank you for your detail reply i just one thing came in your mind that my apache server listen on port 8080 i change this in /etc/apache2/port.conf
because django already running on port so apache can't start on 80 port.
 
Old 08-17-2022, 11:34 PM   #7
elgrandeperro
Member
 
Registered: Apr 2021
Posts: 415
Blog Entries: 2

Rep: Reputation: Disabled
That is why you change django to listen on localhost port 80, and let apache take the inbound network interface ip port 80. Then the proxy ip is localhost 80 and you access django via the proxy.

You change the listen on the apache server to NOT be wild card, just bind it to the ethernet ip port 80.
 
Old 08-17-2022, 11:53 PM   #8
Umeraf
LQ Newbie
 
Registered: Nov 2018
Posts: 26

Original Poster
Rep: Reputation: Disabled
I change the apache port to 80 and run django on 8080 but still same error when i enter abc.com in browser its can't open when enter abc.com:80808 then its open
this is my django app settings
<VirtualHost *:80>
ServerName grepbing.com
ProxyPreserveHost On
ProxyRequests Off
ProxyVia Full

Require all granted
</Proxy>
ProxyPass / http://grepbing.com:8080/
ProxyPassReverse / http://grepbing.com:8080/


</VirtualHost>
 
Old 08-18-2022, 01:31 AM   #9
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,168
Blog Entries: 1

Rep: Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038
Quote:
Originally Posted by Umeraf View Post
I change the apache port to 80 and run django on 8080 but still same error when i enter abc.com in browser its can't open when enter abc.com:80808 then its open
this is my django app settings
<VirtualHost *:80>
ServerName grepbing.com
ProxyPreserveHost On
ProxyRequests Off
ProxyVia Full

Require all granted
</Proxy>
ProxyPass / http://grepbing.com:8080/
ProxyPassReverse / http://grepbing.com:8080/


</VirtualHost>
If both the apache reverse proxy and django run on the same box, it's better to use localhost instead of FQDN. Same goes for the other apps too:
Code:
<VirtualHost *:80>
ServerName grepbing.com
ProxyPreserveHost On
ProxyRequests Off

ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
--other config stuff--
</VirtualHost>
BTW you can use apache2ctl to check the vhosts configured:
Code:
apache2ctl -S
 
Old 08-18-2022, 03:19 AM   #10
Umeraf
LQ Newbie
 
Registered: Nov 2018
Posts: 26

Original Poster
Rep: Reputation: Disabled
I follow your settings but its same problem my all three domains open same site of django not open nodejs or wordpress although nodjs site open with ip:3000 and wordpress also open ip:8080
 
Old 08-18-2022, 03:57 AM   #11
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,168
Blog Entries: 1

Rep: Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038
Quote:
Originally Posted by Umeraf View Post
I follow your settings but its same problem my all three domains open same site of django not open nodejs or wordpress although nodjs site open with ip:3000 and wordpress also open ip:8080
Apparently you didn't create the apache vhosts
Take a look at this howto, to see how to create and enable apache vhosts in Ubuntu (scroll down to step 4 as you don't need document root directories)
 
Old 08-18-2022, 04:12 AM   #12
Umeraf
LQ Newbie
 
Registered: Nov 2018
Posts: 26

Original Poster
Rep: Reputation: Disabled
I have create vhosts the conf files are below
grepbing.com.conf

this is django site
<VirtualHost *:80>
ServerName grepbing.com
ProxyPreserveHost On
ProxyRequests Off
ProxyVia Full
# Servers to proxy the connection, or;
# List of application servers:
# Usage:
# ProxyPass / http://[IP Addr.]:[port]/
# ProxyPassReverse / http://[IP Addr.]:[port]/
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/


</VirtualHost>

hamsantech.com.conf
this is wordpress site
<VirtualHost *:8080>
ServerName hamsantech.com
ServerAdmin webmaster@localhost
ServerAlias www.hamsantech.com
DocumentRoot /var/www/html/hamsantech.com
<Directory /var/www/html/hamsantech.com>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>


kinderbakim.com.conf

This is nodejs site
<VirtualHost *:3000>
ProxyPreserveHost On
ProxyRequests Off
ProxyVia Full

# Servers to proxy the connection, or;
# List of application servers:
# Usage:
# ProxyPass / http://[IP Addr.]:[port]/
# ProxyPassReverse / http://[IP Addr.]:[port]/
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/

ServerName kinderbakim.com

</VirtualHost>

i also enable theses vhosts by this command a2ensite
~
 
Old 08-18-2022, 04:28 AM   #13
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,168
Blog Entries: 1

Rep: Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038Reputation: 2038
Quote:
i also enable theses vhosts by this command a2ensite
So what gives the apache2ctl command I told you to run in my previous post?
Code:
apache2ctl -S
 
Old 08-18-2022, 04:49 AM   #14
Umeraf
LQ Newbie
 
Registered: Nov 2018
Posts: 26

Original Poster
Rep: Reputation: Disabled
Output of the above command
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:80 grepbing.com (/etc/apache2/sites-enabled/grepbing.com.conf:1)
*:8080 hamsantech.com (/etc/apache2/sites-enabled/hamsantech.com.conf:1)
*:3000 kinderbakim.com (/etc/apache2/sites-enabled/kinderbakim.com.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex proxy: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
 
Old 08-18-2022, 04:50 AM   #15
Umeraf
LQ Newbie
 
Registered: Nov 2018
Posts: 26

Original Poster
Rep: Reputation: Disabled
my Apache also running on port 8080 because Django use port 80
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Three Users, Three Window Managers - How? GNewbie Ubuntu 10 03-19-2007 01:23 AM
LXer: Sun Microsystems Delivers Three-in-One Punch to the Competition With World Record Results on Three Operating Systems, Including Solaris 10 LXer Syndicated Linux News 0 02-07-2006 09:46 PM
Three years later, three steps back RAnthony General 1 09-11-2004 04:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration