我的Apache2 Web服务器作为反向代理服务器有问题。我的域为“ example.com”的简化服务器设置如下所示:
如果现在客户转到该页面https://example.com/guacamole
,那么Apache2 Web服务器应将请求转发到Tomcat服务器(https://127.0.0.1:8080/guacamole
)。这部分有效。
如果客户转到https://example.com/mydjangoproject
,则Apache2 Web服务器应使用Gunicorn和Django项目(https://192.168.30.5:8000
)将请求转发到Web服务器。但是,此配置仅部分起作用。该页面https://example.com/mydjangoproject
显示Django项目的主页,但是在调用管理页面时https://example.com/mydjangoproject/admin
,django应用程序给出该页面http://192.168.30.5:8000//admin
不存在的错误。调用管理页面时,似乎已删除了子URL“ / mydjangoproject /”。那会是什么呢?
这是我的配置:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
JKMount /* ajp13_worker
SSLProxyEngine on
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
ProxyPreserveHost On
ProxyPass /static/ !
ProxyPass /mydjangoproject https://192.168.30.5:8000/
ProxyPassReverse /mydjangoproject https://192.168.30.5:8000/
</VirtualHost>
</IfModule>
谢谢你的帮助!
编辑:当我尝试通过进入管理员页面https://example.com/mydjangoproject/admin
时,会发生此错误:
您可能需要更改您的ProxyPass
和ProxyPassReverse
指令才能使其正常工作。
您应该尝试替换以下行:
ProxyPass /static/ !
ProxyPass /mydjangoproject https://192.168.30.5:8000/
ProxyPassReverse /mydjangoproject https://192.168.30.5:8000/
与例如:
# "Convenience" URL
ProxyPass /mydjangoproject https://192.168.30.5:8000
ProxyPassReverse /mydjangoproject https://192.168.30.5:8000
# --- The lines below are what actually allow access to /admin ---
# Proxy /admin for login
ProxyPass /admin http://192.168.30.5:8000/admin
ProxyPassReverse /admin http://192.168.30.5:8000/admin
# Proxy /static for CSS, etc.
ProxyPass /static http://192.168.30.5:8000/static
ProxyPassReverse /static http://192.168.30.5:8000/static
然后,您应该能够使用例如https://example.com/admin
访问您的Django/admin
页面并获得正确的登录对话框:
前任。Django管理员登录
当我尝试通过
https://example.com/mydjangoproject/admin
错误进入管理页面时发生。
您应该能够添加以下行(除了上面推荐的行之外),以使(某些)工作正常进行:
ProxyPass /mydjangoproject/admin http://192.168.30.5:8000
ProxyPassReverse /mydjangoproject/admin http://192.168.30.5:8000
请注意,Django似乎重定向了ex。https://example.com/mydjangoproject/admin
来 https://example.com/admin
自动,这会破坏事物,除非您已经有ex。ProxyPass /admin http://192.168.30.5:8000/admin
作为现有条目(包括在上面)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句