在 vestacp、apache2、mod_wsgi、python 网络应用程序(bottle 框架)上

On vestacp, apache2, mod_wsgi, python web app (bottle framework)

我正在尝试使用 vestacp 面板部署 Bottle 应用程序。我一直收到 500 错误,显然这是由于服务器设置不正确造成的。 我有三个配置文件:

# Adding php wrapper
user=""
domain=""
ip=""
home_dir=""
docroot=""

echo "# Wsgi template
AddHandler wsgi-script .wsgi

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www.\.ru$ [NC]
RewriteRule ^(.*)$ http:///$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /django.wsgi/$1 [QSA,PT,L]
" > $docroot/.htaccess
chown $user:$user $docroot/.htaccess


echo "import os, sys
sys.path.insert(0, '$home_dir/$user/web/$domain/private/django/$domain/env/lib/python2.6/site-packages')
sys.path.insert(0, '$home_dir/$user/web/$domain/private/django/$domain/project/src/shared/')
sys.path.insert(0, '$home_dir/$user/web/$domain/private/django/$domain/project/src/')

os.environ['DJANGO_SETTINGS_MODULE'] = 'main.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()" > $docroot/django.wsgi
chown $user:$user $docroot/django.wsgi

exit 0
    <VirtualHost %ip%:%web_ssl_port%>

    ServerName %domain_idn%
    %alias_string%
    ServerAdmin %email%
    DocumentRoot %sdocroot%
    ScriptAlias /cgi-bin/ %home%/%user%/web/%domain%/cgi-bin/
    Alias /vstats/ %home%/%user%/web/%domain%/stats/
    Alias /error/ %home%/%user%/web/%domain%/document_errors/
    SuexecUserGroup %user% %group%
    CustomLog /var/log/%web_system%/domains/%domain%.bytes bytes
    CustomLog /var/log/%web_system%/domains/%domain%.log combined
    ErrorLog /var/log/%web_system%/domains/%domain%.error.log
    <Directory %home%/%user%/web/%domain%/stats>
        AllowOverride All
    </Directory>
    SSLEngine on
    SSLVerifyClient none
    SSLCertificateFile %ssl_crt%
    SSLCertificateKeyFile %ssl_key%
    %ssl_ca_str%SSLCertificateChainFile %ssl_ca%

    <IfModule mod_ruid2.c>
        RMode config
        RUidGid %user% %group%
        RGroups www-data
    </IfModule>
    <IfModule itk.c>
        AssignUserID %user% %group%
    </IfModule>
    <IfModule mod_wsgi.c>
        WSGIDaemonProcess apx-s$domain% user=%user% group=%user% processes=1 threads=5 display-name=%{GROUP} python-path=%home%/%user%/web/%domain%$        
WSGIProcessGroup apx-idea
        WSGIApplicationGroup %{GLOBAL}
    </IfModule>

    <Directory %sdocroot%>
        AllowOverride FileInfo
        Options ExecCGI Indexes
        MultiviewsMatch Handlers
        Options +FollowSymLinks
        Order allow,deny
        Allow from all
    </Directory>

    IncludeOptional %home%/%user%/conf/web/s%web_system%.%domain%.conf*

</VirtualHost>
<VirtualHost %ip%:%web_port%>

    ServerName %domain_idn%
    %alias_string%
    ServerAdmin %email%
    DocumentRoot %docroot%
    ScriptAlias /cgi-bin/ %home%/%user%/web/%domain%/cgi-bin/
    Alias /vstats/ %home%/%user%/web/%domain%/stats/
    Alias /error/ %home%/%user%/web/%domain%/document_errors/
    SuexecUserGroup %user% %group%
    CustomLog /var/log/%web_system%/domains/%domain%.bytes bytes
    CustomLog /var/log/%web_system%/domains/%domain%.log combined
    ErrorLog /var/log/%web_system%/domains/%domain%.error.log
    <Directory %home%/%user%/web/%domain%/stats>
        AllowOverride All
    </Directory>

    <IfModule mod_ruid2.c>
        RMode config
        RUidGid %user% %group%
        RGroups www-data
    </IfModule>
    <IfModule itk.c>
        AssignUserID %user% %group%
    </IfModule>
    <Directory %docroot%>
        AllowOverride FileInfo
        Options ExecCGI Indexes
        MultiviewsMatch Handlers
        Options +FollowSymLinks
        Order allow,deny
        Allow from all
    </Directory>

    Include %home%/%user%/conf/web/%web_system%.%domain%.conf*

</VirtualHost>

应用程序启动文件 (wsgi.py) 如下所示:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import bottle
import os
import sys

sys.path.append(os.path.dirname(os.path.abspath(__file__)))
os.chdir(os.path.dirname(os.path.abspath(__file__)))

"""С этого файла запускается программа"""
application = bottle.default_app()

Ожидается что настройка конфигурации приведет к сообщению о том что нет определенной директории "/", а=وе к 5.

Error: 404 Not Found
Sorry, the requested URL 'https://some.url/' caused an error:

Not found: '/'

服务器是运行debian 9,vestacp是写这篇文章时的最新版本。 使用此指令配置 wsgi_mod https://forum.vestacp.com/viewtopic.php?t=10867

好的,按照这个说明就可以了 https://forum.vestacp.com/viewtopic.php?t=18352#p76197 和:

  • wsgi.stpl
<VirtualHost %ip%:%web_ssl_port%>

    ServerName %domain_idn%
    %alias_string%
    ServerAdmin %email%
    DocumentRoot %sdocroot%
    ScriptAlias /cgi-bin/ %home%/%user%/web/%domain%/cgi-bin/
    Alias /vstats/ %home%/%user%/web/%domain%/stats/
    Alias /error/ %home%/%user%/web/%domain%/document_errors/
    SuexecUserGroup %user% %group%
    CustomLog /var/log/%web_system%/domains/%domain%.bytes bytes
    CustomLog /var/log/%web_system%/domains/%domain%.log combined
    ErrorLog /var/log/%web_system%/domains/%domain%.error.log
    <Directory %home%/%user%/web/%domain%/stats>
        AllowOverride All
    </Directory>

    SSLEngine on
    SSLVerifyClient none
    SSLCertificateFile %ssl_crt%
    SSLCertificateKeyFile %ssl_key%
    %ssl_ca_str%SSLCertificateChainFile %ssl_ca%

    <IfModule mod_ruid2.c>
        RMode config
        RUidGid %user% %group%
        RGroups www-data
    </IfModule>
    <IfModule itk.c>
        AssignUserID %user% %group%
    </IfModule>
    <IfModule mod_wsgi.c>
        WSGIDaemonProcess apps-%domain% user=%user% group=%user% processes=1 threads=5 display-name=%{GROUP} python-home=%home%/%user%/web/%domain%/private/venv/ python-path=%home%/%user%/web/%domain%/private/%domain% socket-user=%user%
        WSGIProcessGroup apps-%domain%
        WSGIApplicationGroup %{GLOBAL}
        WSGIScriptAlias / %home%/%user%/web/%domain%/private/%domain%/PROJECTAPP/wsgi.py process-group=apps-%domain% application-group=%{GLOBAL}
    </IfModule>

    Alias /robots.txt %home%/%user%/web/%domain%/private/%domain%/static/robots.txt
    Alias /favicon.ico %home%/%user%/web/%domain%/private/%domain%/static/favicon.ico

    Alias /media/ %home%/%user%/web/%domain%/private/%domain%/media/
    Alias /static/ %home%/%user%/web/%domain%/private/%domain%/static/

    <Directory %home%/%user%/web/%domain%/private/%domain%/static>
        Require all granted
    </Directory>

    <Directory %home%/%user%/web/%domain%/private/%domain%/media>
        Require all granted
    </Directory>

    <Directory %sdocroot%>
        AllowOverride FileInfo
        Options ExecCGI Indexes
        MultiviewsMatch Handlers
        Options +FollowSymLinks
        Order allow,deny
        Allow from all
    </Directory>

#    <Directory %home%/%user%/web/%domain%/private/%domain%/PROJECTAPP>
#        <Files wsgi.py>
#            Require all granted
#        </Files>
#    </Directory>

    IncludeOptional %home%/%user%/conf/web/%web_system%.%domain%.ssl.conf*

</VirtualHost>


  • wsgi.tpl
<VirtualHost %ip%:%web_port%>

    ServerName %domain_idn%
    %alias_string%
    ServerAdmin %email%
    DocumentRoot %docroot%
    ScriptAlias /cgi-bin/ %home%/%user%/web/%domain%/cgi-bin/
    Alias /vstats/ %home%/%user%/web/%domain%/stats/
    Alias /error/ %home%/%user%/web/%domain%/document_errors/
    SuexecUserGroup %user% %group%
    CustomLog /var/log/%web_system%/domains/%domain%.bytes bytes
    CustomLog /var/log/%web_system%/domains/%domain%.log combined
    ErrorLog /var/log/%web_system%/domains/%domain%.error.log
    <Directory %home%/%user%/web/%domain%/stats>
        AllowOverride All
    </Directory>

    <IfModule mod_ruid2.c>
        RMode config
        RUidGid %user% %group%
        RGroups www-data
    </IfModule>
    <IfModule itk.c>
        AssignUserID %user% %group%
    </IfModule>
    <IfModule mod_wsgi.c>
        WSGIDaemonProcess app-%domain% user=%user% group=%user% processes=1 threads=5 display-name=%{GROUP} python-home=%home%/%user%/web/%domain%/private/venv/ python-path=%home%/%user%/web/%domain%/private/%domain% socket-user=%user%
        WSGIProcessGroup app-%domain%
        WSGIApplicationGroup %{GLOBAL}
        WSGIScriptAlias / %home%/%user%/web/%domain%/private/%domain%/PROJECTAPP/wsgi.py process-group=app-%domain% application-group=%{GLOBAL}
    </IfModule>

    Alias /robots.txt %home%/%user%/web/%domain%/private/%domain%/static/robots.txt
    Alias /favicon.ico %home%/%user%/web/%domain%/private/%domain%/static/favicon.ico

    Alias /media/ %home%/%user%/web/%domain%/private/%domain%/media/
    Alias /static/ %home%/%user%/web/%domain%/private/%domain%/static/

    <Directory %home%/%user%/web/%domain%/private/%domain%/static>
        Require all granted
    </Directory>

    <Directory %home%/%user%/web/%domain%/private/%domain%/media>
        Require all granted
    </Directory>

    <Directory %docroot%>
        AllowOverride FileInfo
        Options ExecCGI Indexes
        MultiviewsMatch Handlers
        Options +FollowSymLinks
        Order allow,deny
        Allow from all
    </Directory>

#    <Directory %home%/%user%/web/%domain%/private/%domain%/PROJECTAPP>
#        <Files wsgi.py>
#            Require all granted
#        </Files>
#    </Directory>

    IncludeOptional %home%/%user%/conf/web/%web_system%.%domain%.conf*

</VirtualHost>