- 1 year ago
Setting up apache virtual hosts for two django websites on windows server
Comment
1 / 1
To set up Apache virtual hosts for two Django websites on Windows Server, follow these steps:
Install Apache:
- Download the Apache HTTP Server for Windows from the Apache website (https://httpd.apache.org/download.cgi).
- Follow the installation instructions to install Apache on your Windows Server.
Install mod_wsgi:
- Download the appropriate version of mod_wsgi for Windows from the mod_wsgi website (https://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi).
- Install mod_wsgi using pip:
Replacephppip install mod_wsgi-<version>-cp<python_version>-cp<python_version>m-win_<architecture>.whl
<version>
,<python_version>
, and<architecture>
with the corresponding values for the downloaded mod_wsgi package.
Configure Apache:
- Open the Apache configuration file (
httpd.conf
) located in the Apache installation directory (e.g.,C:\Apache24\conf\httpd.conf
). - Uncomment the following line by removing the
#
at the beginning:bashLoadModule wsgi_module modules/mod_wsgi.so
- Add the following lines at the end of the configuration file to define the virtual hosts for your Django websites:
Replaceapache<VirtualHost *:80>
ServerName www.example1.com
ServerAlias example1.com
DocumentRoot "C:/path/to/example1"
WSGIScriptAlias / "C:/path/to/example1/example1/wsgi.py"
<Directory "C:/path/to/example1">
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName www.example2.com
ServerAlias example2.com
DocumentRoot "C:/path/to/example2"
WSGIScriptAlias / "C:/path/to/example2/example2/wsgi.py"
<Directory "C:/path/to/example2">
Require all granted
</Directory>
</VirtualHost>
www.example1.com
andwww.example2.com
with the domain names or hostnames you want to use for your Django websites. ModifyC:/path/to/example1
andC:/path/to/example2
to the actual paths of your Django project directories.
- Open the Apache configuration file (
Restart Apache:
- Open a command prompt as an administrator.
- Navigate to the Apache installation directory (e.g.,
C:\Apache24\bin
). - Run the following command to restart Apache:
httpd.exe -k restart
Update Hosts File:
- Open the hosts file (
C:\Windows\System32\drivers\etc\hosts
) as an administrator. - Add the following lines to map the domain names to the local server IP address:
127.0.0.1 www.example1.com
127.0.0.1 www.example2.com
- Open the hosts file (
Test the Setup:
- Open a web browser and access
http://www.example1.com
andhttp://www.example2.com
to test your Django websites.
- Open a web browser and access
By following these steps, you can set up Apache virtual hosts for two Django websites on Windows Server. Adjust the configuration file paths, domain names, and project directories according to your specific setup.