我已连接到我所在大学的 LAN,其 IP 地址为172.16.123.12
。我正尝试在 apache 服务器上部署一个 flask 应用程序,以便整个校园都可以看到该网站。我已使用 mod_wsgi 成功部署了该应用程序,但我无法在 LAN 上工作。它在 上运行良好,localhost/flask
但我自己无法在http://127.0.1.1/flask
或上访问该网站,http://172.16.123.12/flask
但“它有效”的 apache 页面可以从 和http://127.0.1.1
访问http://172.16.123.12
这是我的 Flask 站点的虚拟主机配置 -
<VirtualHost *:80>
ServerName localhost
WSGIDaemonProcess flask_test threads=5
WSGIScriptAlias /flask /var/www/flask_test/flask.wsgi
ErrorLog "/var/www/flask_test/error.log"
CustomLog "/var/www/flask_test/access.log" combined
<Directory /var/www/flask_test>
WSGIProcessGroup flask_test
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
主机文件:
127.0.0.1 localhost
127.0.1.1 Linux
我也尝试将 ServerName 更改为我的 ipaddress,但无济于事。有人能告诉我我哪里做错了吗?非常感谢!
apapch2ctl -S 的输出
/usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted)
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server 127.0.1.1 (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost 127.0.1.1 (/etc/apache2/sites-enabled/000-default:1)
port 80 namevhost Linux (/etc/apache2/sites-enabled/flasktest:1)
Syntax OK
答案1
ServerName
localhost
意味着只有通过localhost
域请求时才能访问您的应用。
删除该ServerName
行并将您的配置移到VirtualHost
部分,然后重试。
/etc/httpd/conf.d/flask.conf
(基于 Red Hat)/etc/apache2/conf.d/flask.conf
(基于 Debian)WSGIDaemonProcess flask_test threads=5 WSGIScriptAlias /flask /var/www/flask_test/flask.wsgi <Directory /var/www/flask_test> WSGIProcessGroup flask_test WSGIApplicationGroup %{GLOBAL} Order deny,allow Allow from all </Directory>