是否可以在与其他页面(如wordpress)相同的URL中创建flask Webapp? [英] Can I create a flask webapp in the same url with other pages(like wordpress)?

查看:44
本文介绍了是否可以在与其他页面(如wordpress)相同的URL中创建flask Webapp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个仅用于我的局域网的自托管服务器,具有一个Wordpress(miservidor.com)和Owncloud(miservidor.com/owncloud)页面,这些页面运行良好,最近我决定创建一个带有flask的webapp在与miservidor.com/musicdownloader相同的域下.我试图使其正常运行,但没有任何结果,我的配置文件如下:

I have a self-hosted server, only for my lan, with a Wordpress(miservidor.com) and Owncloud(miservidor.com/owncloud) page, those pages work perfectly, and i recentlly decided to create a webapp with flask under the same domain like miservidor.com/musicdownloader. I have tried to make it works but with no results, my config files are these:

/etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
    ServerName miservidor.com
    Redirect / https://miservidor.com/
</VirtualHost>

/etc/apache2/sites-available/default-ssl.conf

<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                ServerAdmin webmaster@localhost

                DocumentRoot /var/www/html

                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined

                SSLEngine on

                SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
                SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key

                <FilesMatch "\.(cgi|shtml|phtml|php)$">
                                SSLOptions +StdEnvVars
                </FilesMatch>
                <Directory /usr/lib/cgi-bin>
                                SSLOptions +StdEnvVars
                </Directory>
                <Directory />
                        AllowOverride ALL
                </Directory>
        </VirtualHost>
</IfModule>

/etc/apache2/config-available/musicdownloader.conf

<VirtualHost *:80>
                WSGIScriptAlias /musicdownloader /var/www/musicdownloader/musicdownloader.wsgi
                <Directory /var/www/musicdownloader/musicdownloader/>
                        Order allow,deny
                        Allow from all
                </Directory>
                Alias /musicdownloader/static /var/www/musicdownloader/musicdownloader/static
                <Directory /var/www/musicdownloader/musicdownloader/static/>
                        Order allow,deny
                        Allow from all
                </Directory>
                ErrorLog ${APACHE_LOG_DIR}/error.log
                LogLevel warn
                CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

/etc/apache2/config-available/owncloud.conf

Alias /owncloud "/var/www/owncloud/"

<Directory /var/www/owncloud/>
  Options +FollowSymlinks
  AllowOverride All

 <IfModule mod_dav.c>
  Dav off
 </IfModule>

 SetEnv HOME /var/www/owncloud
 SetEnv HTTP_HOME /var/www/owncloud

</Directory>

我的Web应用程序层次结构是(在/var/www/中):

My web app hierarchy is (in /var/www/):

|--musicdownloader/
|----musicdownloader.wgsi
|----musicdownloader/
|------app.py
|------static/
|--------main.css
|------templates/
|--------musicdownloader.html
|--------download.html

musicdownloader.wgsi

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/musicdownloader/")

from musicdownloader import app as application

app.py

from flask import Flask, render_template, request

app = Flask(__name__)

@app.route('/musicdownloader', methods=["POST","GET"])
def musicdownloader():
    return render_template('musicdownloader.html')

if __name__ == "__main__":
    app.run()

这是正确的方法吗?最好使用具有相同IP的子域或不同域?预先感谢.

Is this the correct way to do it? It is better to use subdomains or different domains with the same ip? Thanks in advance.

推荐答案

我找到了解决方案,可以通过将放在/etc/apache2/config-available/musicdownloader.conf文件中的内容更改为:

I found the solution, I can do it by changing the content I put in the file /etc/apache2/config-available/musicdownloader.conf to:

WSGIScriptAlias /musicdownloader /var/www/musicdownloader/musicdownloader.wgsi

WSGIDaemonProcess musicdownloader python-path=/var/www/musicdownloader:/var/www/musicdownloader/musicdownloader/venv/lib/python3.8/site-packages
WSGIProcessGroup musicdownloader

<Directory /var/www/musicdownloader/musicdownloader/>
     Require all granted
</Directory>
Alias /musicdownloader/static /var/www/musicdownloader/musicdownloader/static
<Directory /var/www/musicdownloader/musicdownloader/static/>
Require all granted
</Directory>

然后:

sudo systemctl reload apache2

现在我可以在我的烧瓶应用程序中使用了

And now I can have my flask app in:

miservidor.com/musicdownloader

这篇关于是否可以在与其他页面(如wordpress)相同的URL中创建flask Webapp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆