403 error forbidden you don't have permission to access /myapp on this server mod_wsgi and apache
403 error forbidden you don't have permission to access /myapp on this server mod_wsgi and apache
我已将 mod_wsgi 安装为 Apache 模块,我想 运行 一个简单的 hello world 应用程序以查看该模块是否正常工作。
我关注了this guide, which is based on the official Quick Configuration Guide.
完成所有步骤后,我收到 403 错误
Forbidden You don't have permission to access /myapp on this server.
.
我在 Raspbian 上使用 Apache/2.4.10,我安装的 mod_wsgi 版本是
libapache2-mod-wsgi-py3 4.3.0-1 armhf Python 3 WSGI adapter module for Apache.
我已将 example.com 添加到我的主机文件中,如下所示:
127.0.0.1 localhost example.com
我在 /etc/apache2/sites-enabled/
中创建了 example.com.conf 文件,内容为:
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
ServerAdmin test@test.com
DocumentRoot /usr/local/www/documents
<Directory /usr/local/www/documents>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.wsgi
<Directory /usr/local/www/wsgi-scripts>
Order allow,deny
Allow from all
</Directory>
myapp.wsgi内容:
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!\n'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
并使用以下权限为 hello world 应用程序创建 files/folders:
drwxr-sr-x 2 root www-data 4096 Feb 1 13:18 documents
drwxr-sr-x 2 root www-data 4096 Feb 1 13:22 wsgi-scripts
我还确保 example.com 在本地提供服务,而不是通过 DNS 使用 ping。
我不明白为什么我的安装不起作用。
是否缺少任何其他配置选项或我的任何设置有问题?
经过几次修改,我想通了。
新的 example.com.conf
文件是:
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /usr/local/www/documents
<Directory /usr/local/www/documents>
Require all granted
Satisfy Any
</Directory>
WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.wsgi
<Directory /usr/local/www/wsgi-scripts>
<Files myapp.wsgi>
Require all granted
Satisfy Any
</Files>
</Directory>
语法更改以匹配 apache 2.4 后,我收到 500 Internal Server Error,在进一步调查 apache error.log
文件后,该错误指示以下错误:
[wsgi:error] [pid 11216] [client 127.0.0.1:56642] mod_wsgi (pid=11216): Exception occurred processing WSGI script '/usr/local/www/wsgi-scripts/myapp.wsgi'.
[wsgi:error] [pid 11216] [client 127.0.0.1:56642] TypeError: sequence of byte string values expected, value of type str found
为了解决这个错误,我将 myapp.wsgi
文件中的 output
变量赋值从 output = 'Hello World!\n'
更改为
到 output = b'Hello World!'
,因为它被指示 here。
我已将 mod_wsgi 安装为 Apache 模块,我想 运行 一个简单的 hello world 应用程序以查看该模块是否正常工作。
我关注了this guide, which is based on the official Quick Configuration Guide.
完成所有步骤后,我收到 403 错误
Forbidden You don't have permission to access /myapp on this server.
.
我在 Raspbian 上使用 Apache/2.4.10,我安装的 mod_wsgi 版本是
libapache2-mod-wsgi-py3 4.3.0-1 armhf Python 3 WSGI adapter module for Apache.
我已将 example.com 添加到我的主机文件中,如下所示:
127.0.0.1 localhost example.com
我在 /etc/apache2/sites-enabled/
中创建了 example.com.conf 文件,内容为:
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
ServerAdmin test@test.com
DocumentRoot /usr/local/www/documents
<Directory /usr/local/www/documents>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.wsgi
<Directory /usr/local/www/wsgi-scripts>
Order allow,deny
Allow from all
</Directory>
myapp.wsgi内容:
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!\n'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
并使用以下权限为 hello world 应用程序创建 files/folders:
drwxr-sr-x 2 root www-data 4096 Feb 1 13:18 documents
drwxr-sr-x 2 root www-data 4096 Feb 1 13:22 wsgi-scripts
我还确保 example.com 在本地提供服务,而不是通过 DNS 使用 ping。
我不明白为什么我的安装不起作用。
是否缺少任何其他配置选项或我的任何设置有问题?
经过几次修改,我想通了。
新的 example.com.conf
文件是:
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /usr/local/www/documents
<Directory /usr/local/www/documents>
Require all granted
Satisfy Any
</Directory>
WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.wsgi
<Directory /usr/local/www/wsgi-scripts>
<Files myapp.wsgi>
Require all granted
Satisfy Any
</Files>
</Directory>
语法更改以匹配 apache 2.4 后,我收到 500 Internal Server Error,在进一步调查 apache error.log
文件后,该错误指示以下错误:
[wsgi:error] [pid 11216] [client 127.0.0.1:56642] mod_wsgi (pid=11216): Exception occurred processing WSGI script '/usr/local/www/wsgi-scripts/myapp.wsgi'.
[wsgi:error] [pid 11216] [client 127.0.0.1:56642] TypeError: sequence of byte string values expected, value of type str found
为了解决这个错误,我将 myapp.wsgi
文件中的 output
变量赋值从 output = 'Hello World!\n'
更改为
到 output = b'Hello World!'
,因为它被指示 here。