I have an app that functions properly on my local wamp server using the virtual host configuration seen below. I recently purchased shared hosting, but unlike my localhost, I dont have access to Apache's httpd-vhost.conf and instead must manipulate the site root's .htaccess file in order to "wire up" my application properly.
The problem is that I do not know how to use the RewriteEngine to write RewriteRules that can emulate (to some degree) this virtual host config:
<VirtualHost *:80>
ServerName sitename
ServerAdmin webmaster#localhost
DocumentRoot "c:/wamp/www/siteroot"
AliasMatch /(.*)\.(js|css|rdf|xml|ico|txt|gif|html|png|jpg|jpeg|json|eot|woff|svg|ttf|pdf)$ "c:/wamp/www/siteroot/app/$1.$2"
AliasMatch /rest/(.*) "c:/wamp/www/siteroot/rest/$1"
AliasMatch /img/(.*) "c:/wamp/www/siteroot/app/img/$1"
AliasMatch /(.*) "c:/wamp/www/siteroot/app/index.php"
ErrorLog "logs/sitename_app_error.log"
LogLevel warn
CustomLog "logs/sitename_app_access.log combined" %a
</VirtualHost>
<VirtualHost *:80>
ServerName admin.sitename
ServerAdmin webmaster#localhost
DocumentRoot "c:/wamp/www/siteroot"
AliasMatch /app/(.*)\.(js|css|rdf|xml|ico|txt|gif|html|png|jpg|jpeg|json|eot|woff|svg|ttf|pdf)$ "c:/wamp/www/siteroot/app/$1.$2"
AliasMatch /i18n/(.*)\.json$ "/wamp/www/siteroot/app/i18n/$1.json"
AliasMatch /(.*)\.(js|css|rdf|xml|ico|txt|gif|html|png|jpg|jpeg|json|eot|woff|svg|ttf|pdf|csv)$ "c:/wamp/www/siteroot/adminApp/$1.$2"
AliasMatch /rest/(.*) "c:/wamp/www/siteroot/rest/$1"
AliasMatch /img/(.*) "c:/wamp/www/siteroot/adminApp/img/$1"
AliasMatch /(.*) "c:/wamp/www/siteroot/adminApp/index.html"
ErrorLog "logs/sitename_app_error.log"
LogLevel warn
CustomLog "logs/sitename_app_access.log combined" %a
</VirtualHost>
<Directory "c:/wamp/www/siteroot">
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "c:/wamp/www/siteroot/app">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
<Directory "c:/wamp/www/siteroot/adminApp">
AuthName "Login required"
AuthType Basic
AuthUserFile "c:/wamp/www/siteroot/adminApp/.htpasswd"
AuthGroupFile "/dev/null"
Require valid-user
</Directory>
<Directory "c:/wamp/www/siteroot/rest">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
*note that sitename and siteroot aren't the actual names of the site/filepath.
The aliasMatches are what's most important for my site to "work." This is why I think I can get by using the RewriteRules in .htaccess.
Even if you aren't familiar with RewriteRules, if you could tell me what the regular expressions mean, that would be of great help too! Any assistance is appreciated!
Related
Hi Guys I am trying to route my domain to server 139.5X.X.XXX
Following is My DNS record Details in Hostinger :-
Type Name Priority Content IP-V4 TTL
A www 0 139.5X.X.XXX 600
A # 0 139.5X.X.XXX 14400
Now I am seeing default apache page while browsing the domain (Server serving default apache page (Digital Ocean Ubuntu Droplet)) .
But after configuring a Django service to domain it taking too long to respond and ending up with "This Site can't be Reached"
following is the conf file which I am using
<VirtualHost *:80>
ServerName tellie.in
ServerAlias www.tellie.in
Redirect permanent / https://tellie.in/
RewriteEngine on
RewriteCond %{SERVER_NAME} =tellie.in [OR]
RewriteCond %{SERVER_NAME} =www.tellie.in
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin admin#tellie.in
ServerName tellie.in
ServerAlias www.tellie.in
DocumentRoot /home/srv/telli
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /home/srv/telli/telli/static
<Directory /home/srv/telli/telli/static>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Alias /media /home/srv/telli/telli/media
<Directory /home/srv/telli/telli/media>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /home/srv/telli/telli/telli>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess telli python-path=/home/srv/telli/telli python-home=/home/srv/telli/venv
WSGIProcessGroup telli
WSGIScriptAlias / /home/srv/telli/telli/telli/wsgi.py
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/tellie.in/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/tellie.in/privkey.pem
</VirtualHost>
Is there anything wrong that could cause the problem I am facing
Make sure that Apache has rx access to the directories under /home/srv/, It is better to move the code out of HOME and in a general mountpoint as /var or /data
I've setup SSL certification on AWS.
However, this seems to be automatically redirecting to https rather than hitting our vhosts file..
The pages are erroring out with the following...
mixed Content: The page at 'https://preprod-example.co.uk/' was loaded over HTTPS, but requested an insecure stylesheet 'http://preprod-example.co.uk/modules/system/system.base.css?ow428z'. This request has been blocked; the content must be served over HTTPS.
The vhosts file:
<VirtualHost *:80>
DocumentRoot "/var/www/html/example/production"
ServerName preprod-example.co.uk
<Directory /var/www/html/example/production>
order allow,deny
allow from all
AllowOverride all
</Directory>
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "/var/www/html/example/production"
ServerName preprod-example.co.uk
<Directory /var/www/html/example/production>
order allow,deny
allow from all
AllowOverride all
</Directory>
</VirtualHost>
Where am I going wrong or is this maybe an issue with AWS?
SetEnvIf X-Forwarded-Proto "^https$" HTTPS=on
you can use SetEnvif just before your 443 virtual host
<VirtualHost *:80>
DocumentRoot "/var/www/html/example/production"
ServerName preprod-example.co.uk
<Directory /var/www/html/example/production>
order allow,deny
allow from all
AllowOverride all
</Directory>
</VirtualHost>
SetEnvIf X-Forwarded-Proto "^https$" HTTPS=on
<VirtualHost *:443>
DocumentRoot "/var/www/html/example/production"
ServerName preprod-example.co.uk
<Directory /var/www/html/example/production>
order allow,deny
allow from all
AllowOverride all
</Directory>
</VirtualHost>
I am very new to bitnami/apache/aws and have recently been assigned with figuring out why 3 of our sites are redirecting to one specific site. I have spent countless hours on this and i think i have narrowed it down to the app.conf files. Even when i try to access the /wp-admin or /administrator urls it take me to the other site. Here are two of the app.conf files. Let me know if anything looks out of place. Thanks in advance.
Main site all others are redirecting to
<VirtualHost *:80>
DocumentRoot /opt/bitnami/apps/www.blueleafdef.com/htdocs
ServerName blueleafdef.com
ServerAlias www.blueleafdef.com
ServerAlias blueleafdefr.uat.ignitedev.com
ErrorLog /opt/bitnami/apps/www.blueleafdef.com/log/error.log
CustomLog /opt/bitnami/apps/www.blueleafdef.com/log/access.log common
<Directory "/opt/bitnami/apps/www.blueleafdef.com/htdocs">
Options +Indexes +FollowSymLinks -MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory> </VirtualHost>
One example of other site
<VirtualHost *>
DocumentRoot /opt/bitnami/apps/www.fuelsnews.com/htdocs
ServerName www.fuelsnews.com:80
ServerAlias www.fuelsnews.com
ErrorLog /opt/bitnami/apps/www.fuelsnews.com/log/error.log
CustomLog /opt/bitnami/apps/www.fuelsnews.com/log/access.log common
<Directory "/opt/bitnami/apps/www.fuelsnews.com/htdocs">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory> </VirtualHost>
<VirtualHost *>
DocumentRoot /opt/bitnami/apps/www.fuelsnews.com/htdocs
ServerName fuelsnews.com:80
ServerAlias fuelsnews.com
ErrorLog /opt/bitnami/apps/www.fuelsnews.com/log/error.log
CustomLog /opt/bitnami/apps/www.fuelsnews.com/log/access.log common
<Directory "/opt/bitnami/apps/www.fuelsnews.com/htdocs">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory> </VirtualHost>
<VirtualHost *>
DocumentRoot /opt/bitnami/apps/www.fuelsnews.com/htdocs
ServerName fuelsnewsr.uat.ignitedev.com:80
ServerAlias fuelsnewsr.uat.ignitedev.com
ErrorLog /opt/bitnami/apps/www.fuelsnews.com/log/error.log
CustomLog /opt/bitnami/apps/www.fuelsnews.com/log/access.log common
<Directory "/opt/bitnami/apps/www.fuelsnews.com/htdocs">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory> </VirtualHost>
Use below and restart the apache it will work.
<VirtualHost *>
DocumentRoot /opt/bitnami/apps/www.fuelsnews.com/htdocs
ServerName www.fuelsnews.com
ServerAlias fuelsnews.com
ErrorLog /opt/bitnami/apps/www.fuelsnews.com/log/error.log
CustomLog /opt/bitnami/apps/www.fuelsnews.com/log/access.log common
<Directory "/opt/bitnami/apps/www.fuelsnews.com/htdocs">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory> </VirtualHost>
<VirtualHost *>
DocumentRoot /opt/bitnami/apps/www.fuelsnews.com/htdocs
ServerName fuelsnewsr.uat.ignitedev.com
ServerAlias fuelsnewsr.uat.ignitedev.com
ErrorLog /opt/bitnami/apps/www.fuelsnews.com/log/error.log
CustomLog /opt/bitnami/apps/www.fuelsnews.com/log/access.log common
<Directory "/opt/bitnami/apps/www.fuelsnews.com/htdocs">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory> </VirtualHost>
Is there a way for Django to pass through some urls to whatever apache would resolve them too?
For instance, if I type in: http://< my-ip >. Is there a way to have django just serve up whatever is in /var/www/html/index.html?
Similarly, if I type in http://< my-ip >/devel, is there a way to make django simply serve what's in /var/www/html/devel/?
Basically, I want some urls to "not be touched".
Thanks!
Edit
Following Anentropic's comment, I'd like Apache to call Django only if it can't match the url. How would I need to change httpd.conf to do that? Let's say I want Django to respond to only /polls/, /admin/ and /accounts/.
Here's the relevant portion from my httpd conf file:
<VirtualHost *:80>
#DocumentRoot /home/ec2-user/srv/mysite
DocumentRoot /var/www/html/
ServerName <My IP ADDRESS>
WSGIScriptAlias / /home/ec2-user/srv/mysite/apache/wsgi.py
# Alias /phpmyadmin /var/www/html/phpmyadmin
# <Location /phpmyadmin>
# SetHandler None
# </Location>
<Directory /home/ec2-user/srv/mysite/media>
Order deny,allow
Allow from all
</Directory>
<Directory /home/ec2-user/srv/mysite/apache>
Order deny,allow
Allow from all
</Directory>
LogLevel warn
Alias /media/ /home/ec2-user/srv/mysite/media/
Alias /static/ /home/ec2-user/srv/mysite/static/
<Directory /home/ec2-user/srv/mysite/static>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
If you'd like to serve static html pages you could use the flatpages app.
Again if you'd like to use different languages (php etc) I believe that you'd have to set up different virtual host in you apache config file to catch the url before it gets served to Django and redirect it to the correct folder. i.e:
<VirtualHost *:80>
ServerName staging.mydomain.com
DocumentRoot /var/www/html/mydomain.com/staging/
</VirtualHost>
<VirtualHost *:80>
ServerName dev.mydomain.com
DocumentRoot /var/www/html/mydomain.com/dev/
</VirtualHost>
EDIT
<VirtualHost *:80>
#DocumentRoot /home/ec2-user/srv/mysite
DocumentRoot /var/www/html/
ServerName <My IP ADDRESS>
Alias /phpmyadmin /var/www/html/phpmyadmin
<Location /phpmyadmin>
SetHandler None
</Location>
<Directory /home/ec2-user/srv/mysite/media>
Order deny,allow
Allow from all
</Directory>
<Directory /home/ec2-user/srv/mysite/apache>
Order deny,allow
Allow from all
</Directory>
LogLevel warn
WSGIScriptAlias /polls /home/ec2-user/srv/mysite/apache/wsgi.py
WSGIScriptAlias /admin /home/ec2-user/srv/mysite/apache/wsgi.py
WSGIScriptAlias /accounts /home/ec2-user/srv/mysite/apache/wsgi.py
Alias /media/ /home/ec2-user/srv/mysite/media/
Alias /static/ /home/ec2-user/srv/mysite/static/
<Directory /home/ec2-user/srv/mysite/static>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
I am a newbie in php using the framework codeigniter.
I want my servername to be directed to the welcome page of codeigniter.
And while setting up the vhost,
I had problems in vhost servername.
Everytime I access it, it redirects to the wampserver homepage.
I tried configuring it in the httpd-vhost.conf using this:
<VirtualHost 127.0.0.1>
DocumentRoot "C:/wamp/www"
ServerName localhost
</VirtualHost>
<VirtualHost 127.0.0.1>
DocumentRoot "C:/wamp/www/mysite"
ServerName mysite.com
</VirtualHost>
I uncomment the Include conf/extra/httpd-vhosts.conf line
I also included the domain name in windows host file.
127.0.0.1 mysite.com
But still, every time I access mysite.com, it shows the wampserver homepage instead of the welcome page of codeigniter.
You need to uncomment:
NameVirtualHost *:80
in httpd-vhosts.conf. Maybe even make it
NameVirtualHost *
Make sure to use FollowSymLinks
<Directory "c:/wamp/www">
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
and even make two virtual hosts.. one for domain.com
<VirtualHost *:80>
ServerName domain.com
DocumentRoot C:/wamp/www/domain
ErrorLog C:/wamp/www/domain/logs/error.log
CustomLog C:/wamp/www/domain/logs/access.log common
<Directory "c:/wamp/www">
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and again for www.domain.com
<VirtualHost *:80>
ServerName www.domain.com
ServerAlias www.domain.com
DocumentRoot C:/wamp/www/domain
ErrorLog C:/wamp/www/domain/logs/werror.log
CustomLog C:/wamp/www/domain/logs/waccess.log common
<Directory "c:/wamp/www">
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
be sure you've created all the folders for the log files.
And btw I'm not 100% sure all of this will work.
Good resources on this topic:
Wamp Server: Multiple Virtual Hosts are not working on Windows
http://www.dennisplucinik.com/blog/2007/08/16/setting-up-multiple-virtual-hosts-in-wamp/