Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用apache2部署django_Python_Django_Apache - Fatal编程技术网

Python 使用apache2部署django

Python 使用apache2部署django,python,django,apache,Python,Django,Apache,(我有点不知所措)我正试图在apache2上部署我的django服务器。我已经构建了一个相当大的前端应用程序(目前与apache2一起部署),不希望通过django提供任何视图,而是希望将后端作为服务主体 我已按照这里的说明: 在modwsgi部分之后,我在apache日志文件中得到了以下内容: [Tue May 20 12:19:44 2014] [notice] Apache/2.2.22 (Debian) PHP/5.4.4-14+deb7u8 mod_wsgi/3.4 Python

(我有点不知所措)我正试图在apache2上部署我的django服务器。我已经构建了一个相当大的前端应用程序(目前与apache2一起部署),不希望通过django提供任何视图,而是希望将后端作为服务主体

我已按照这里的说明:

在modwsgi部分之后,我在apache日志文件中得到了以下内容:

  [Tue May 20 12:19:44 2014] [notice] Apache/2.2.22 (Debian) PHP/5.4.4-14+deb7u8 mod_wsgi/3.4 Python/2.7.3 configured -- resuming normal operations
将其附加到apache配置文件后:

LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

WSGIScriptAlias / /var/www/PhotodiceServer/PhotodiceServer/wsgi.py
WSGIPythonPath /var/www/PhotodiceServer

<Directory /var/www/PhotodiceServer/PhotodiceServer>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
这是URL.py文件的内容:

from django.conf.urls import patterns, include, url
from django.contrib.auth.models import User, Group
from rest_framework import viewsets, routers

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browseable API.
url(r'^admin/', include(admin.site.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
)
# ViewSets define the view behavior.
class UserViewSet(viewsets.ModelViewSet):
model = User

class GroupViewSet(viewsets.ModelViewSet):
model = Group


# Routers provide an easy way of automatically determining the URL conf.
router = routers.DefaultRouter()
router.register(r'users', UserViewSet)
router.register(r'groups', GroupViewSet)
这是已安装的应用程序:

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'photod',
)
以前,当我输入Web服务器的ip(树莓pi)时,我被自动路由到存储在var/www/中的index.html

现在,当我输入webserve的ip时,我得到了404页面未找到,我是否必须明确地说什么url将以某种方式加载静态文件?这将如何影响角向布线?(我使用过angular ui router.js)


(如果我设置debug=False,则会得到错误的请求(400)

我认为您在Apache配置中缺少一些东西:

  • AddHandler wsgi script.py
  • Options+ExecCGI
    SetHandler wsgi脚本
  • 试试这些,看看上面写的是什么

    编辑***因为您显然不熟悉apache

    LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
    
    AddHandler wsgi-script .py
    WSGIScriptAlias / /var/www/PhotodiceServer/PhotodiceServer/wsgi.py
    WSGIPythonPath /var/www/PhotodiceServer
    
    <Directory /var/www/PhotodiceServer/PhotodiceServer>
        Options +ExecCGI
        <Files wsgi.py>
            Order deny,allow
            Allow from all
        </Files>
    </Directory>
    

    LoadModule wsgi_module/usr/lib/apache2/modules/mod_wsgi.so
    AddHandler wsgi script.py
    WSGIScriptAlias//var/www/PhotodiceServer/PhotodiceServer/wsgi.py
    WSGIPythonPath/var/www/PhotodiceServer
    选项+执行CGI
    命令拒绝,允许
    通融
    
    另一次编辑***

    这是我使用的配置(虽然最后我只是运行了uWSGI服务器并将代理传递给它,因为这有点痛苦!!)

    
    ServerName my.local.domain
    SetEnv应用程序\环境开发
    别名/favicon.ico/path/to/project/favicon.ico
    别名匹配^/static/(.*)$/path/to/project/static/$1
    AddHandler wsgi script.py
    WSGIScriptAlias//path/to/project/project/wsgi.py
    WSGIDaemonProcess\u WSGI user=chazmead group=www data processes=1 threads=5 python path=/path/to/project/venv/lib/python2.7/site packages:/path/to/project
    WSGIProcessGroup\u WSGI
    SetHandler wsgi脚本
    选项索引跟随SYMLINKS ExecCGI
    命令允许,拒绝
    通融
    
    几个问题:为什么使用过时的指南(页面顶部有红色警告,请尝试使用实际指南:)。另一个问题是:为什么是Apache?有更好的替代方案,如Nginx(更好的性能、安全性等),发布您的实际配置可能非常有用,而不仅仅是您遵循的指南的链接。这意味着:您的Apache.conf文件,以及您安装Django应用程序的方式/位置。谢谢,我在更改为其他指南后编辑了这篇文章。为什么是apache?我叫约翰·斯诺(我什么都不知道)。我已经在我的var/www指令中安装了django应用程序。。。我想使用starproject命令。。。我已经尝试配置了一段时间,不记得确切的
    内部服务器错误
    表示您的应用程序配置中有一些错误。你能把你的
    wsgi.py
    的内容放在这里吗?还要尝试在应用程序的设置中设置
    DEBUG=True
    ,这样任何请求都会显示错误回溯,而不是简洁的错误消息。此外,您还可以尝试在该服务器上运行
    manage.py runserver
    (是否可以,权限?),并在该服务器上基于控制台的浏览器中显示该页面(链接),或将其存储在html文件wget(
    wget)中http://localhost:8000
    )看起来您要做的是使用django作为angular的REST后端。有一本通读的书,告诉你怎么做。这个问题也很有用;我删除了这个标签,因为这个问题不是关于角度,而是用mod_wsgi设置django。恰巧你正在使用angular作为django应用程序的前端,但它与此无关;你在一篇文章中也问了多个问题。请把帖子限制在一个(可回答的)问题上。2是什么意思。?或选项+ExecCGI SetHandler wsgi脚本。。。。LoadModule wsgi_module/usr/lib/apache2/modules/mod_wsgi.so WSGIScriptAlias//var/www/PhotodiceServer/PhotodiceServer/PhotodiceServer/wsgi.py WSGIPythonPath/var/www/PhotodiceServer AddHandler wsgi script.py Options+ExecCGI SetHandler wsgi脚本Order deny,allow-allow-from-Still404@BAYELK查看最近的编辑!如果它对您有效,请不要忘记将其标记为正确。感谢您的编辑,但这并不能解决任何问题:/t请尝试添加一个空的url处理程序:
    url(r“^$”,“app.views.view”)
    LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
    
    AddHandler wsgi-script .py
    WSGIScriptAlias / /var/www/PhotodiceServer/PhotodiceServer/wsgi.py
    WSGIPythonPath /var/www/PhotodiceServer
    
    <Directory /var/www/PhotodiceServer/PhotodiceServer>
        Options +ExecCGI
        <Files wsgi.py>
            Order deny,allow
            Allow from all
        </Files>
    </Directory>
    
    <VirtualHost *:80>
        ServerName my.local.domain
    
        SetEnv APPLICATION_ENV development
    
        Alias /favicon.ico /path/to/project/favicon.ico
    
        AliasMatch ^/static/(.*)$ /path/to/project/static/$1
    
        AddHandler wsgi-script .py
        WSGIScriptAlias / /path/to/project/project/wsgi.py
    
        WSGIDaemonProcess _WSGI user=chazmead group=www-data processes=1 threads=5 python-path=/path/to/project/venv/lib/python2.7/site-packages:/path/to/project
        WSGIProcessGroup _WSGI
    
        <Directory "/path/to/project/project/">
            SetHandler wsgi-script
            Options Indexes FollowSymLinks ExecCGI
    
            Order Allow,Deny
            Allow from all
        </Directory>
    
    </VirtualHost>