Host multiple web sites on port 80 - django

So I may be missing a bit of a fundamental understanding on what's going on here, but I cannot get this to work. I have two django websites, and I want to be able to host them both on the same box, both on port 80. Is there some magic to get this to work properly? Here's what my sites-available/default file looks like:
<VirtualHost *:80>
WSGIScriptAlias / /path/to/proj/apache/django.wsgi
AliasMatch ^/([^/]*\.css) /path/to/proj/static/
Alias /media /path/to/proj/static/
Alias /static/ /path/to/proj/static/
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
WSGIScriptAlias / /path/to/otherproj/apache/django.wsgi
ErrorLog ${APACHE_LOG_DIR}/error2.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Obviously this doesn't work since navigating to the site hits the first one and it never goes to the second one. So my question is, how do I set this up so I can host 2 web sites on port 80. Perhaps I could do like localhost/site1 and localhost/site2 and figure it out that way, but no matter what I try I can't seem to get that to work.
I have played with the ServerName property, but I don't really understand how that can work, setting it doesn't seem to change that hitting the ip of that machine only shows the first website, and I don't know where using the ServerName affects anything.
Any suggestions, or let me know if I need to give more information.
Also note they both work if I change the second one to port 8080, but when doing that I can't seem to put a domain name on top of myip:8080.

I don't think there is anything to explain here. You just need to actually specify the name of each virtual domain.
Note:NameVirtualHost is deprecated
<VirtualHost *:80>
ServerName site1.ltd
WSGIScriptAlias / /path/to/proj/apache/django.wsgi
AliasMatch ^/([^/]*\.css) /path/to/proj/static/
Alias /media /path/to/proj/static/
Alias /static/ /path/to/proj/static/
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName site2.ltd
WSGIScriptAlias / /path/to/otherproj/apache/django.wsgi
ErrorLog ${APACHE_LOG_DIR}/error2.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Related

how to host multiple virtual hosts from same IP address in Apache server over AWS?

I want to host two different angular panels over Apache (AWS). So I disabled the default 000-default.conf file in etc/apache2/sites-available using a2dissite 000-default.conf and made two files webAdmin.conf and webUIpanel.conf. Now my webAdmin.conf has the following configuration
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/AngularProjects/getItHomeNow_UI/dist
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
and webUIpanel.conf has following
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/AngularProjects/getItHomeNow_UserPanel/dist
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Then I used a2ensite to enable both config files and at last sudo systemctl restart apache2. But one of them working at a time. I need to disable one to make other work. Kindly suggest me where did I go wrong?
You should add ServerName in your VirtualHost config so Apache can decide which site should get the request. So to apply that to your config it should look like:
webAdmin.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/AngularProjects/getItHomeNow_UI/dist
ServerName www.example1.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
and webUIpanel.conf has following
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/AngularProjects/getItHomeNow_UserPanel/dist
ServerName www.example2.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
NOTE: Both ServerName should be valid domains so they resolve to your server or use your /etc/hosts file to point them to your server IP.

How to redirect google VM external ip address to HTTPS in django with Debial and Apache?

I have successfully installed SSL certificate with certbot and lets encrypt on my debian and apache linux virtual machine on google cloud.
the domain is successfully secure with HTTPS.
Although on directly accessing the external ip address i am still getting an unsecure version of the website.
How to redirect the ip directly to the HTTPS version set up with APACHE and just the "domain.com" towards -->> HTTPs:www.domain.com .
I have tried to re-route to port 80 and 443 towards the HTTPS version as in PHP without any luck as shown here :
How to redirect from www to https www with htacces?
in my 000-default.conf:
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster#localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.bracketline.com [OR]
RewriteCond %{SERVER_NAME} =localhost
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI}
[END,NE,R=permanent]
</VirtualHost>
and on my 000-default-le-ssl.conf i have:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName localhost
ServerAdmin webmaster#localhost
Alias /static /var/www/static-root
<Directory /var/www/static-root>
Require all granted
</Directory>
Alias /media /var/www/media-root
<Directory /var/www/media-root>
Require all granted
</Directory>
<Directory /var/www/venv/src/cfehome>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess cfehome python-
path=/var/www/venv/src/:/var/www/venv/lib/python3.5/site-packages
WSGIProcessGroup cfehome
WSGIScriptAlias / /var/www/venv/src/cfehome/wsgi.py
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerAlias www.bracketline.com
SSLCertificateFile
/etc/letsencrypt/live/www.bracketline.com/fullchain.pem
SSLCertificateKeyFile
/etc/letsencrypt/live/www.bracketline.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
I am not sure how this thing works if a detailed blog or turorial could be given it would be of great help. thanx in advance!
First lacate which .conf file youre actually using by typing apachectl -S (this works on Debian based OS'es).
Next up edit the file, it should look simillar:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
Protocols h2 http/1.1
# SSL Configuration
# Other Apache Configuration
</VirtualHost>
In general there are several tutorials how to configure HTTP to HTTPS redirect:
Redirect HTTP to HTTPS in Apache
How to Redirect HTTP to HTTPS on Apache
Apache Redirect to HTTPS
And some interesting discusson Why is my Apache VirtualHost directing to the wrong VirtualHost?
Lastly - here's another SO discussion on that topic that has an accepted answer.
Those are just recent (up to 2 years old) examples that will help you and there are dozens more if they won't answer your questions.

How to configure subdomain to specific port

I have two projects 1: is wordpress running on apache (main website thespatio.com/45.33.10.149)
2: A Django Application running on Nginx using same IP with 81 port. (45.33.10.149:81). I want to configure above two apps so that when some one hit http://thespatio.com it should show main website and if some hit http://or.thespatio.com it should show my django application. I have seen many fix but none work for me. I tried virtual host like proxypass and proxy_reverse but apache stopped working. below are the two virtual hosts conf file
Main Website settings (conf)
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName thespatio.com
ServerAlias www.thespatio.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Django App (conf)
<VirtualHost *:80>
ServerAdmin admin#test.com
ServerName or.thespatio.com
ServerAlias www.thespatio.com
ProxyPass / http://or.thespatio.com:81/
ProxyPassReverse / http://or.thespatio.com:81/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Any help would be appreciated. Thanks in advance
mod_proxy was not installed. I follow Install mod_proxy tutorial and my both apps working fine.

WAMP virtual host error log location not working?

Haven't used WAMP in years, but decided to try it again today for a project I am going to work on. I have everything setup and working, but for some reason the error log locations I am defining in my virtual host file are not working - all log entries still go to the default files at c:\wamp64\logs\ rather than the custom ones I specified below.
My vhost file is :
# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerName site.local
ServerAlias site.local
DocumentRoot "C:/Users/Support/Documents/My Web Sites/BS4/site.com"
<Directory "C:/Users/Support/Documents/My Web Sites/BS4/site.com">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
ErrorLog "logs/site.local-error.log"
CustomLog "logs/site.local-access.log" common
</VirtualHost>
Am I missing something here? I want to have different logs for each 'project' I am working on (only one defined for now), but having them separate makes more sense.
Change your definition of the log files to include the full path.
You might also like to add a seperate log file for the PHP error log.
ErrorLog "C:/wamp/logs/localhost-error.log"
CustomLog "C:/wamp/logs/localhost-access.log" common
php_value error_log "C:/wamp/logs/localhost.php.error.log"
and
ErrorLog "C:/wamp/logs/site.local-error.log"
CustomLog "C:/wamp/logs/site.local-access.log" common
php_value error_log "C:/wamp/logs/site.php.error.log"

mod_wsgi problem or?

i have apache2.conf
<VirtualHost 91.218.230.130:8080>
ServerName dopisaka.ru
DocumentRoot /var/www/dopisalki.ru/data/www/dopisaka.ru
SuexecUserGroup dopisalki.ru dopisalki.ru
CustomLog /var/www/httpd-logs/dopisaka.ru.access.log combined
ErrorLog /var/www/httpd-logs/dopisaka.ru.error.log
ServerAlias www.dopisaka.ru
ServerAdmin 911#dopisalki.ru
AddDefaultCharset utf-8
<Directory "/var/www/dopisalki.ru/data/www/dopisaka.ru">
Order allow,deny
Allow from all
</Directory>
Alias /manager/ "/var/www/dopisalki.ru/data/www/dopisaka.ru/manager/"
ScriptAlias /cgi-bin/ /var/www/dopisalki.ru/data/www/dopisaka.ru/cgi-bin/
WSGIScriptAlias / /var/www/dopisalki.ru/data/www/dopisaka.ru/django.wsgi
</VirtualHost>
but http://www.dopisaka.ru/ show just a "Index of".
whats wrong?
You have included an IP address in the VirtualHost directive. Did you provide a compatible NameVirtualHost directive using that IP address along with the port? If you didn't then likely that the VirtualHost configuration isn't being used at all, and instead the default virtual host definition is being used and it is that which is set up to return the index. More often that not using an IP address in VirtualHost is not what you want to do and you should just use '*:8080', still remembering though that you need a matching NameVirtualHost directive.
Try to remove the DocumentRoot directive. Also your wsgi script seem to be under DocumentRoot, you don't want the script under DocumentRoot because that make it readable by everyone.