Django + Apache,在此服务器上找不到请求的URL / admin /

时间:2018-08-20 03:02:41

标签: django mod-wsgi

我正在Django项目上工作,并尝试在Apache上托管,但是发生了“在此服务器上找不到请求的URL / admin /。”,我读了tutorial的vhost和wsgi配置:

服务器环境: CentOS 7.5,Apache 2.4,Python 3.6,Django 1.11.15并在虚拟环境中运行。 当我激活virtualenv并使用内置服务器时,项目运行正常。

python manage.py runserver 192.168.99.70:8080

我发现Apache错误日志上生成了一个错误:

[wsgi:error] Target WSGI script not found or unable to stat: /root/psbookingproject/psbooking/psbooking

但是我不知道如何解决路径问题。

我的项目文件夹结构: enter image description here

Apache vhost.conf

Listen 8080
<VirtualHost 192.168.99.70:8080>
    # This is name based virtual hosting. So place an appropriate server name
    #   here. Example: django.devsrv.local
    ServerName  psbooking.com
    ServerAdmin admin@sample.com

    # This alias makes serving static files possible.
    #   Please note, that this is geared to our settings/common.py
    #   In production environment, you will propably adjust this!
    Alias /static/  /root/psbookingproject/static/

    # This alias makes serving media files possible.
    #   Please note, that this is geared to our settings/common.py
    #   In production environment, you will propably adjust this!
    Alias /media/  /root/psbookingproject/media/

    # Insert the full path to the wsgi.py-file here
    WSGIScriptAlias /   /root/psbookingproject/psbooking/PSBookingBackend/wsgi.py

    # PROCESS_NAME specifies a distinct name of this process
    #   see: https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess
    # PATH/TO/PROJECT_ROOT is the full path to your project's root directory, 
    #   containing your project files
    # PATH/TO/VIRTUALENV/ROOT: If you are using a virtualenv specify the full
    #   path to its directory.
    #   Generally you must specify the path to Python's site-packages.
    WSGIDaemonProcess   psbooking20180820  python-path=/root/psbookingproject:/root/psbookingproject/psbookingenv/lib/python3.6/site-packages

    # PROCESS_GROUP specifies a distinct name for the process group
    #   see: https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIProcessGroup
    WSGIProcessGroup    psbooking

    # Serving static files from this directory
    #   Please note, that this is geared to our settings/common.py
    #   In production environment, you will propably adjust this!
    <Directory /root/psbookingproject/static>
        Options -Indexes
        Order deny,allow
        Allow from all
    </Directory>

    # Serving media files from this directory
    #   Please note, that this is geared to our settings/common.py
    #   In production environment, you will propably adjust this!
    <Directory /root/psbookingproject/media>
        Options -Indexes
        Order deny,allow
        Allow from all
    </Directory>

    LogLevel info

    # PROJECT_NAME is used to seperate the log files of this application
    ErrorLog    /var/log/httpd/psbooking_error.log
    CustomLog   /var/log/httpd/psbooking_access.log combined
</VirtualHost>

url.py

from django.conf.urls import include, url
from django.views.static import serve
from django.contrib import admin
from PSBookingBackend.settings import MEDIA_URL, MEDIA_ROOT
from django.views.generic import TemplateView

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = [
    # Examples:
    # url(r'^$', PSBookingBackend.views.home, name='home'),
    # url(r'^PSBookingBackend/', include('PSBookingBackend.PSBookingBackend.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
     url(r'^admin/', include(admin.site.urls)),
     url(r'^$', TemplateView.as_view(template_name='index.html')),
]

# Api url
api_patterns = [
    url(r'^api/merchants/', include('merchants.urls')),
    url(r'^api/shops/', include('shops.urls')),
    url(r'^api/users/', include('users.urls')),
    url(r'^api/services/', include('services.urls')),
    url(r'^api/service-bookings/', include('service_bookings.urls')),
    url(r'^api/notifications/', include('notifications.urls')),
    url(r'^api/app_contents/', include('app_contents.urls'))
]

media_patterns = [
        url(r'^media/(?P<path>.*)$', serve, {
            'document_root': MEDIA_ROOT,
        }),
    ]

urlpatterns += api_patterns
urlpatterns += media_patterns

wsgi.py

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PSBookingBackend.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)

0 个答案:

没有答案