简体   繁体   English

在同一Apache服务器上运行Django和Flask

[英]Running django and flask on same apache server

I am trying to run to run django and flask on the same apache server. 我试图在同一台Apache服务器上运行django和flask。

WSGISocketPrefix /var/www/wsgi
<VirtualHost *:80>
        ServerAdmin name@email.com
        ServerName  domain.com
        ServerAlias www.domain.com
        DocumentRoot /var/www/
        LogLevel warn
        WSGIDaemonProcess apache processes=2 maximum-requests=500 threads=1
        WSGIProcessGroup apache
        Alias /media /var/www/media/

        WSGIScriptAlias / /var/www/djangoapps/django.wsgi
        WSGIScriptAlias /app1 /var/www/flaskapps/app.wsgi
</VirtualHost>
  1. The first WSGIScriptAlias runs a django app in the root: domain.com. 第一个WSGIScriptAlias在根目录domain.com中运行django应用程序。
  2. The second instance of WSGIScriptAlias needs to run a flask app in a subdomain: app1 . WSGIScriptAlias的第二个实例需要在以下子域中运行flask应用程序: app1

But since the main site sits over django, when I try to hit: domain.com/app1 , django's urls.py tries to handle that url command. 但是由于主站点位于django上,因此当我尝试点击时: domain.com/app1urls.py尝试处理该url命令。 But urls.py should not handle it, since its an independent flask app. 但是urls.py不应该处理它,因为它是一个独立的flask应用程序。

Any ideas how can I go about it? 有什么想法可以解决吗?

I'm not sure if this would solve the problem, but have you tried changing the order of your script alias so that /app1 is found before / ? 我不知道这是否会解决这个问题,但你试图改变你的脚本别名的顺序,以便/app1被发现前/

WSGISocketPrefix /var/www/wsgi
<VirtualHost *:80>
        ServerAdmin name@email.com
        ServerName  domain.com
        ServerAlias www.domain.com
        DocumentRoot /var/www/
        LogLevel warn
        WSGIDaemonProcess apache processes=2 maximum-requests=500 threads=1
        WSGIProcessGroup apache
        Alias /media /var/www/media/
        WSGIScriptAlias /app1 /var/www/flaskapps/app.wsgi
        WSGIScriptAlias / /var/www/djangoapps/django.wsgi

</VirtualHost>

For anyone who want to achieve the same in 2018 this really helped me: 对于想要在2018年实现相同目标的任何人,这确实帮助了我:

https://www.phusionpassenger.com/library/deploy/apache/deploy/python/ https://www.phusionpassenger.com/library/deploy/apache/deploy/python/

I know it is off topic, but I found this question like 20 searches before I found the link to the Description from Passenger.... 我知道这是题外话,但是在找到“乘客说明”的链接之前,我发现了20个搜索问题。

How ev's here is an excert from the tutorial: 这里的ev是本教程的专家:

<VirtualHost *:80>
    ServerName www.phusion.nl
    DocumentRoot /websites/phusion/public
<Directory /websites/phusion>
    Allow from all
    Options -MultiViews
    # Uncomment this if you're on Apache >= 2.4:
    #Require all granted
</Directory>

Alias /subapp /websites/secondapp/public
<Location /subapp>
    PassengerBaseURI /subapp
    PassengerAppRoot /websites/secondapp

    PassengerAppType wsgi
    PassengerStartupFile passenger_wsgi.py
</Location>
<Directory /websites/secondapp/public>
    Allow from all
    Options -MultiViews
    # Uncomment this if you're on Apache >= 2.4:
    #Require all granted
</Directory>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM