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>
Related
I created a demo for my domain www.example.com which only returns the index as you can see below.
def index(request):
return HttpResponse("This is a demo")
urlpatterns = [
path('admin/', admin.site.urls),
path("",index),
]
I was able to access my site with domain name (I made the "A" dns record in godaddy site) and this was the <VirtualHost *:80>
<VirtualHost *:80>
ServerName loopingaround.com
ServerAlias www.loopingaround.com
ErrorLog /django-pro/site/logs/error.log
CustomLog /django-pro/site/logs/access.log combine
alias /static /django-pro/site/public/static
<Directory /django-pro/site/public/static>
Require all granted
</Directory>
alias /media /django-pro/site/public/media
<Directory /django-pro/site/public/media>
Require all granted
</Directory>
<Directory /django-pro/src/tutorial>
Require all granted
</Directory>
WSGIDaemonProcess tutorial python-home=/django-pro/venv python-path=/django-pro/src/
WSGIProcessGroup tutorial
WSGIScriptAlias / /django-pro/src/tutorial/wsgi.py
</VirtualHost>
then I used "ssl for free" for creating a ssl certificate for my site and set the files they provided.
<VirtualHost *:80>
ServerName loopingaround.com
ServerAlias www.loopingaround.com
Redirect / https://loopingaround.com
</VirtualHost>
<VirtualHost *:443>
ServerName loopingaround.com
ServerAlias www.loopingaround.com
ErrorLog /django-pro/site/logs/error.log
CustomLog /django-pro/site/logs/access.log combine
SSLEngine on
SSLCertificateFile /etc/ssl/certificate.crt
SSLCertificateKeyFile /etc/ssl/private/private.key
SSLCertificateChainFile /etc/ssl/ca_bundle.crt
alias /static /django-pro/site/public/static
<Directory /django-pro/site/public/static>
Require all granted
</Directory>
alias /media /django-pro/site/public/media
<Directory /django-pro/site/public/media>
Require all granted
</Directory>
<Directory /django-pro/src/tutorial>
Require all granted
</Directory>
WSGIDaemonProcess tutorial python-home=/django-pro/venv python-path=/django-pro/src/
WSGIProcessGroup tutorial
WSGIScriptAlias / /django-pro/src/tutorial/wsgi.py
</VirtualHost>
now even if I revert the changes I made, I cannot access my site as before (I am restarting apache2 service everytime) nor I can access it using https
if possible please tell me my mistakes and how I can also implement ssl for my django project to return 403.
My site is working on http
I now want it to work using a SSl certificate. I've generated the keys and set up the virtualhost:
<VirtualHost *:80>
WSGIDaemonProcess pms python-path=/home/ubuntu/myapp/myapp:/home/ubuntu/myapp/env/lib/python3.4$
WSGIProcessGroup myapp
WSGIScriptAlias / /home/ubuntu/myapp/myapp/myapp/wsgi.py
<Directory /home/ubuntu/myapp/myapp/myapp>
<Files wsgi.py>
Require all granted
</Files>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ServerAdmin support#myapp.com
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/ca.crt
SSLCertificateKeyFile /etc/apache2/ssl/ca.key
ServerName leanhotelsystem.com
ServerAlias *.leanhotelsystem.com
DocumentRoot /home/ubuntu/myapp/myapp/myapp
<Directory /home/ubuntu/myapp/myapp/myapp>
<Files wsgi.py>
Require all granted
</Files>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerAdmin support#myapp.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I've also set in wsgi.py:
os.environ['HTTPS'] = "on"
and in settings.py:
WSGI_APPLICATION = 'myapp.wsgi.application'
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
The problem is that when i access the url with https it shows my folder structure, instead of rendering the homepage.
If I access via http it works fine.
Thanks!
Looks like you forget your WSGI settings section in your new 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/
I have domain name and I have set virtual host I want to know how to connect the domain name to my virtual host I'm new to this so plz answer easy understandable answers
http-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "C:/wamp/www">
Order Deny,Allow
Deny from all
Allow from localhost
</Directory>
</VirtualHost>
<VirtualHost example.com>
DocumentRoot "C:/wamp/www/example"
ServerName example.com
ServerAlias example.com
Options Indexes FollowSymLinks
<Directory C:/wamp/www>
Order Deny,Allow
Allow from all
</Directory>
</VirtualHost>
I want to show the website using domain name internal and external
Ok so lets assume your domain is called mysite.com and you also need a testing version of the site, lets say mysite.dev
You have used Apache 2.2 syntax so I assume you are using a version of Apache that is 2.2.x, however if you are using Apache 2.4.x see below for correct syntax
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
<Directory "C:/wamp/www">
AllowOverride All
Order Deny,Allow
Deny from all
Allow from localhost
</Directory>
</VirtualHost>
# This is for accessing a development version of the site
# note: only accessible from this machine
<VirtualHost *:80> <-- change
DocumentRoot "C:/wamp/www/mysite.test"
ServerName mysite.dev
<Directory "C:/wamp/www/mysite.test">
Options Indexes FollowSymLinks <-- moved
Order Deny,Allow
Deny from all
Allow from localhost 127.0.0.1 ::1
</Directory>
</VirtualHost>
#New Virtual Host for your real domain name
#accessible from the internet
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/mysite.com"
ServerName mysite.com
ServerAlias www.mysite.com
<Directory "C:/wamp/www/mysite.com">
Options Indexes FollowSymLinks
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
If you are using Apache 2.4.x then the syntax should be chabged like so :-
#NameVirtualHost *:80 <- not required in apache 2.4
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
<Directory "C:/wamp/www">
AllowOverride All
Require local
</Directory>
</VirtualHost>
# This is for accessing a development version of the site
# note: only accessible from this machine and stored in different folder
<VirtualHost *:80> <-- change
DocumentRoot "C:/wamp/www/mysite.test"
ServerName example.dev
<Directory "C:/wamp/www/mysite.test">
Options Indexes FollowSymLinks <-- moved
Require local
</Directory>
</VirtualHost>
#New Virtual Host for your real domain name
#accessible from the internet
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/mysite.com"
ServerName mysite.com
ServerAlias www.mysite.com
<Directory "C:/wamp/www/mysite.com">
Options Indexes FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
You will need to add the mysite.dev site to the windows HOSTS file c:\windows\system32\drivers\etc\hosts but NOT the live domain name
127.0.0.1 localhost
127.0.0.1 mysite.dev
::1 localhost
::1 mysite.dev