[英]403 - Forbidden with Apache and Django on Windows with mod_wsgi
I have looked through numerous tutorials and posts related to Apache and Django on Windows to try to solve my issue. 我浏览了许多与Windows上的Apache和Django相关的教程和帖子,以尝试解决我的问题。 I can run the Django project via the development server and know that my Apache install is working. 我可以通过开发服务器运行Django项目,并且知道我的Apache安装正在运行。 I know that my issue resides in the configuration of Apache to get it to work with Django. 我知道我的问题出在Apache的配置中,以使其可与Django一起使用。 My configuration is shown below. 我的配置如下所示。 I have made sure that the server project folder is accessible to Everyone with read and execute permissions. 我已确保具有读取和执行权限的每个人都可以访问服务器项目文件夹。 I have tried setting the paths with the "C:" and without. 我尝试用“ C:”设置路径,不使用。 Setting the server's filesystem directory access to "Require all granted" (not recommended) does not help. 将服务器的文件系统目录访问权限设置为“要求全部授予”(不建议)无济于事。 What am I missing? 我想念什么?
Django settings.py Django settings.py
ALLOWED_HOSTS = ['*']
WSGI_APPLICATION = 'INDmain.wsgi.application'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
httdp.conf httdp.conf
Include conf/extra/httpd-vhosts.conf # "#" is removed from start of line.
LoadFile "c:/users/user/appdata/local/programs/python/python36/python36.dll"
LoadModule wsgi_module "c:/users/user/appdata/local/programs/python/python36/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win_amd64.pyd"
WSGIPythonHome "c:/users/user/appdata/local/programs/python/python36"
WSGIScriptAlias / "C:/INDmain/main/wsgi.py
WSGIPythonPath "C:/INDmain"
<Directory "C:/INDmain/main">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
httpd-vhosts.conf 的httpd-vhosts.conf
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
Alias "/" "C:/INDmain/main"
<Directory "C:/INDmain/main">
Require all granted
</Directory>
Alias "/static" "C:/INDmain/static"
<Directory "C:/INDmain/static">
Require all granted
</Directory>
</VirtualHost>
Granted I only implement on Linux, so the following may not be helpful, but my standard approach would be to create a sitename_co_uk.conf
file within /etc/apache2/sites-available
当然,我只在Linux上实现,所以以下内容可能无济于事,但我的标准方法是在/etc/apache2/sites-available
创建sitename_co_uk.conf
文件
The following would be the content of the file: 以下是文件的内容:
<VirtualHost *:80>
ServerAdmin webmaster@sitename.co.uk
ServerName sitename.co.uk
ServerAlias www.sitename.co.uk
DocumentRoot /var/www/sitename
WSGIDaemonProcess sitename python-path=/var/www/sitename python-home=/var/www/sitename/env
WSGIProcessGroup sitename
WSGIScriptAlias / /var/www/sitename/core/wsgi.py
Alias /robots.txt /var/www/sitename/static/robots.txt
Alias /favicon.ico /var/www/sitename/static/favicon.ico
Alias /media/ /var/www/sitename/media/
Alias /static/ /var/www/sitename/static/
<Directory /var/www/sitename/static>
Require all granted
</Directory>
<Directory /var/www/sitename/media>
Require all granted
</Directory>
WSGIScriptAlias / /var/www/sitename/core/wsgi.py
<Directory /var/www/sitename/core>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
This means I have my site actually in the directory /var/www/sitename'. This directory will contain a virtual environment in
这意味着我的网站实际上位于目录/var/www/sitename'. This directory will contain a virtual environment in
/var/www/sitename'. This directory will contain a virtual environment in
env and the
manage.py file. My
/var/www/sitename'. This directory will contain a virtual environment in
env and the
manage.py file. My
/var/www/sitename'. This directory will contain a virtual environment in
file. My
file. My
settings.py ,
wsgi.py etc are within the sub-directory
core`. file. My
settings.py ,
wsgi.py etc are within the sub-directory
core`中。
This is enabled using a2ensite sitename_co_uk.conf
. 这可以使用a2ensite sitename_co_uk.conf
启用。
It should work in a similar fashion on Windows. 在Windows上,它应该以类似的方式工作。
After getting this up and running in a Docker container running Ubuntu, I was able to get my Windows version to work after copying the project into a directory under the Apache directory and making some configuration changes for the new location. 将其安装并运行在运行Ubuntu的Docker容器中后,将项目复制到Apache目录下的目录中并为新位置进行了一些配置更改后,便能够使用Windows版本。 Final configuration files are below. 最终配置文件如下。
Web site/project layout 网站/项目布局
\Apache24
--> www
--> INDapp
--> INDmain
--> INDmain
--> main
db.sqlite3
manage.py
Django settings.py Django settings.py
ALLOWED_HOSTS = ['<ip_address>']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main.apps.MainConfig',
WSGI_APPLICATION = 'INDmain.wsgi.application'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
httdp.conf httdp.conf
LoadFile "c:/users/rsloma/appdata/local/programs/python/python36/python36.dll"
LoadModule wsgi_module "c:/users/rsloma/appdata/local/programs/python/python36/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win_amd64.pyd"
WSGIPythonHome "c:/users/rsloma/appdata/local/programs/python/python36"
WSGIPythonPath C:/Apache24/www/INDapp/INDmain
httpd-vhosts.conf 的httpd-vhosts.conf
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
ServerAlias <ip_address>
DocumentRoot C:/Apache24/www/INDapp
Alias /static "C:/Apache24/www/INDapp/INDmain/main/static"
<Directory "C:/Apache24/www/INDapp/INDmain/main/static">
Require all granted
</Directory>
<Directory "C:/Apache24/www/INDapp/INDmain/INDmain">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / C:/Apache24/www/INDapp/INDmain/INDmain/wsgi.py
</VirtualHost>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.