403-禁止在Windows和Mod_wsgi

时间:2019-03-11 17:27:49

标签: python django windows apache

我浏览了许多与Windows上的Apache和Django相关的教程和帖子,以尝试解决我的问题。我可以通过开发服务器运行Django项目,并且知道我的Apache安装正在运行。我知道我的问题出在Apache的配置中,以使其可与Django一起使用。我的配置如下所示。我已确保具有读取和执行权限的每个人都可以访问服务器项目文件夹。我尝试用“ C:”设置路径,不使用。将服务器的文件系统目录访问权限设置为“要求全部授予”(不建议)无济于事。我想念什么?

Django settings.py

ALLOWED_HOSTS = ['*']
WSGI_APPLICATION = 'INDmain.wsgi.application'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")

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

<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>

2 个答案:

答案 0 :(得分:0)

当然,我仅在Linux上实现,因此以下内容可能无济于事,但我的标准方法是在controller = new TextEditingController(text: "0,00"); 内创建sitename_co_uk.conf文件

以下是文件的内容:

/etc/apache2/sites-available

这意味着我的网站实际上位于<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> env /var/www/sitename'. This directory will contain a virtual environment in manage.py and the settings.py file. My wsgi.py ,核心目录中。

使用etc are within the sub-directory启用了此功能。

它在Windows上应该以类似的方式工作。

答案 1 :(得分:0)

在将其安装并运行在运行Ubuntu的Docker容器中后,将项目复制到Apache目录下的目录中并对新位置进行了一些配置更改后,便能够使用Windows版本。最终配置文件如下。

网站/项目布局

\Apache24
--> www
    --> INDapp
        --> INDmain
            --> INDmain
            --> main
            db.sqlite3
            manage.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

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

<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>