首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Apache 2将转发到具有路由和静态文件的Flask应用程序进行调整

使用Apache 2将转发到具有路由和静态文件的Flask应用程序进行调整
EN

Stack Overflow用户
提问于 2021-09-08 10:38:39
回答 1查看 102关注 0票数 0

有一个在http://servername.com:5000/上运行的烧瓶应用程序。它封装了gis_webapp/static/...中提供的一些引导和静态文件,这是它应该采用的工作方式。

这是该项目的树:

代码语言:javascript
复制
gis_webapp
├── __init__.py
├── routes.py
├── gunicorn_gis_webapp_conf.py
├── static
│   ├── bootstrap-4.6.0-dist
│   │   ├── css
│   │   └── js
│   ├── css
│   │   └── style.css
│   └── img
│       ├── favicon.png
│       └── glogo.gif
└── templates
    ├── about.html
    ├── base.html
    ├── contact.html
    ├── errors
    │   └── 404.html
    ├── index.html
    └── result.html

当我使用必须继承Apache2全部内容的mod_auth_gssapi (通过http://servername.com/ (http://servername.com:80/) )在同一服务器上运行的http://servername.com/gis/应用转发时,就停止工作了:

  1. 线路间通信 当我单击导航栏中的联系人链接时,它会将我带到http://servername.com/contact/ (它不存在),而不是http://servername.com/gis/contact
  2. /static文件夹中的内容
  3. gis_webapp/static/bootstrap-4.6.0-dist文件夹引导

我做错了什么?

.conf文件的内容如下:

代码语言:javascript
复制
<VirtualHost *:80>
    <Location /gis/>
        ProxyPass "http://localhost:5000/"
        ProxyPassReverse "http://localhost:5000/"
    </Location>
</VirtualHost>

我在这些线程中找到了一些建议,并试图应用这些建议:

不幸的是他们没能解决我的问题。

我还试图修改我的routes.py文件中的路径。

代码语言:javascript
复制
# main page
@gis_webapp.route("/", methods=["GET"])
@gis_webapp.route("/index", methods=["GET"])
def index():
    return render_template("index.html", title="GIS")

已改写为:

代码语言:javascript
复制
# main page
@gis_webapp.route("/gis/", methods=["GET"])
@gis_webapp.route("/gis/index", methods=["GET"])
def index():
    return render_template("index.html", title="GIS")

我还找到了这个线程通过apache提供静态文件,它建议应用ALIAS,但是对我来说不是一个解决方案,因为以后Apache2和Flask将出现在不同的服务器上。然而,有一种观点认为:静力学需要由Apache发布,即使您随后将其分散到不同的服务器上,那么最好将静力学安装到Apache所在的位置。

到目前为止,我可以部分地解决2.和3.问题,并在“base.html”中进行调整,因此本文引用:

代码语言:javascript
复制
<link rel="icon" type="image/png" href="/static/img/favicon.png">

改为:

代码语言:javascript
复制
<link rel="icon" type="image/png" href="/gis/static/img/favicon.png">

因此,之后我可以在/static页面上看到http://servername.com/gis/文件夹的内容,但是当我通过http://servername.com:5000/打开它时,它就消失了。不明白为什么。有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-28 13:05:27

解决方案是按照SCRIPT_NAME中的建议部署古尼坎变量和这篇文章变量

代码语言:javascript
复制
SCRIPT_NAME="/gis" gunicorn --bind=0.0.0.0:5000 gis_webapp:gis_webapp

之后,我可以通过http://servername.com/gis/访问应用程序。

然而,初始的URL http://servername.com:5000/正在产生Internal Server Error。要克服这一问题,只需使用http://servername.com:5000/gis/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69101533

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档