Hamoud
By:
Hamoud

deploying flask application on different sub domain

March 3, 2015 2.7k views
VPN Apache Getting Started Server Optimization Configuration Management Ubuntu

hello i followed the tutorial on how to deploy flask in Ubuntu.

and i successfully deployed two application on same server as following :
site.com/abc -->Application 1
site.com/efg -->Application 2

but i tried to deploy it using sub domain as abc.site.com and efg.site.com but unfortunately what i'm getting is that they both point to the same app !

abc.site.com -->App 1
efg.site.com -->App 1

here's my site conf

code


WSGIPythonPath /var/www/AppX_User/public_html/App1/V1:/var/www/AppY_User/public_html/App1/V1

<VirtualHost *:80>
    ServerAdmin webmaster@example.com
        ServerName X.site.com
        DocumentRoot /var/www/AppX_User/public_html
    WSGIScriptAlias / var/www/AppX_User/public_html/App1/V1/App1.wsgi
    <Directory var/www/AppX_User/public_html/App1>
        Order allow,deny
        Allow from all
    </Directory>
        ErrorLog ${APACHE_LOG_DIR}/X_error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/Y_access.log combined

</VirtualHost>
<VirtualHost *:80>

    ServerAdmin webmaster@example.com
        ServerName Y.site.com
        DocumentRoot /var/www/AppY_User/public_html
    WSGIScriptAlias / var/www/AppY_User/public_html/App1/V1/App1.wsgi
    <Directory /var/www/AppY_User/public_html/App1>
        Order allow,deny
        Allow from all
    </Directory>
        ErrorLog ${APACHE_LOG_DIR}/Y_error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/Y_access.log combined
</VirtualHost>
4 comments
  • Can you post the real config please? This is impossible to read because we can't tell if the mistakes are real or edits.

  • WSGIPythonPath /var/www/Salon/publichtml/App1/V1:/var/www/Barber/publichtml/App1/V1

    <VirtualHost *:80>
    ServerAdmin webmaster@example.com
    ServerName Salon.serme.me
    DocumentRoot /var/www/Salon/publichtml
    WSGIScriptAlias / /var/www/Salon/public
    html/App1/V1/App1.wsgi
    <Directory /var/www/Salon/public_html/App1>
    Order allow,deny
    Allow from all
    </Directory>
    ErrorLog ${APACHELOGDIR}/Salonerror.log
    LogLevel warn
    CustomLog ${APACHE
    LOGDIR}/Salonaccess.log combined

    </VirtualHost>
    <VirtualHost *:80>

    ServerAdmin webmaster@example.com
        ServerName Barber.serme.me
        DocumentRoot /var/www/Barber/public_html
    WSGIScriptAlias / /var/www/Barber/public_html/App1/V1/App1.wsgi
    <Directory /var/www/Barber/public_html/App1>
        Order allow,deny
        Allow from all
    </Directory>
        ErrorLog ${APACHE_LOG_DIR}/Barber_error.log
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/Barber_access.log combined
    

    </VirtualHost>

  • @gp+digitalocean
    WSGIPythonPath /var/www/Salon/publichtml/App1/V1:/var/www/Barber/publichtml/App1/V1

    <VirtualHost *:80>
    ServerAdmin webmaster@example.com
    ServerName Salon.serme.me
    DocumentRoot /var/www/Salon/publichtml
    WSGIScriptAlias / /var/www/Salon/publichtml/App1/V1/App1.wsgi
    <Directory /var/www/Salon/public_html/App1>
    Order allow,deny
    Allow from all
    </Directory>
    ErrorLog ${APACHELOGDIR}/Salonerror.log
    LogLevel warn
    CustomLog ${APACHELOGDIR}/Salonaccess.log combined

    </VirtualHost>
    <VirtualHost *:80>

    ServerAdmin webmaster@example.com
    ServerName Barber.serme.me
    DocumentRoot /var/www/Barber/publichtml
    WSGIScriptAlias / /var/www/Barber/public
    html/App1/V1/App1.wsgi
    <Directory /var/www/Barber/public_html/App1>
    Order allow,deny
    Allow from all
    </Directory>
    ErrorLog ${APACHELOGDIR}/Barbererror.log
    LogLevel warn
    CustomLog ${APACHE
    LOGDIR}/Barberaccess.log combined

    </VirtualHost>

  • I would like to run two separate flask applications.
    I followed the instructions as indicated in below link
    https://www.digitalocean.com/community/questions/running-mutliple-flask-application

    After I save *.conf file, and run: sudo service apache2 restart,
    my webpage gives following error:
    http://www.datascience2.com/flaskapp/
    Not Found

    The requested URL /flaskapp/ was not found on this server.

    NOTE: When I ran the init.py for just one flask application, it did work. It just doesn't seem to work when I try to add another flask application.

    Are you able to look at my *.conf file and init.py files and see where the error is?
    I followed the instructions exactly. It may just be a minor syntax issue. When I run it with just one flask application, it does work. It's just when I try to do 2 that it doesn't work.

    WSGIPythonPath /var/www/FlaskApp:/var/www/FlaskMetis

    <VirtualHost *:80>
    ServerName datascience2.com
    ServerAdmin temp@xxx.com

                WSGIScriptAlias /FlaskApp /var/www/FlaskApp/flaskapp.wsgi
                <Directory /var/www/FlaskApp/FlaskApp/>
                        Order allow,deny
                        Allow from all
                </Directory>
    
                Alias /Flaskapp/static /var/www/FlaskApp/FlaskApp/static
                <Directory /var/www/FlaskApp/FlaskApp/static/>
                        Order allow,deny
                        Allow from all
                </Directory>
    
                WSGIScriptAlias /FlaskMetis /var/www/FlaskMetis/flaskapp.wsgi
                <Directory /var/www/FlaskMetis/FlaskMetis/>
                        Order allow,deny
                        Allow from all
                </Directory>
    
                Alias /FlaskMetis/static /var/www/FlaskMetis/FlaskMetis/static
                <Directory /var/www/FlaskMetis/FlaskMetis/static/>
                        Order allow,deny
                        Allow from all
                </Directory>
    
                ErrorLog ${APACHE_LOG_DIR}/error.log
                LogLevel warn
                CustomLog ${APACHE_LOG_DIR}/access.log combined
    

    </VirtualHost>

    <VirtualHost *:80>
    ServerName www.datascience2.com
    ServerAdmin temp@xxx.com

                WSGIScriptAlias /FlaskApp /var/www/FlaskApp/flaskapp.wsgi
                <Directory /var/www/FlaskApp/FlaskApp/>
                        Order allow,deny
                        Allow from all
                </Directory>
    
                Alias /Flaskapp/static /var/www/FlaskApp/FlaskApp/static
                <Directory /var/www/FlaskApp/FlaskApp/static/>
                        Order allow,deny
                        Allow from all
                </Directory>
    
                WSGIScriptAlias /FlaskMetis /var/www/FlaskMetis/flaskapp.wsgi
                <Directory /var/www/FlaskMetis/FlaskMetis/>
                        Order allow,deny
                        Allow from all
                </Directory>
    
                Alias /FlaskMetis/static /var/www/FlaskMetis/FlaskMetis/static
                <Directory /var/www/FlaskMetis/FlaskMetis/static/>
                        Order allow,deny
                        Allow from all
                </Directory>
                ErrorLog ${APACHE_LOG_DIR}/error.log
                LogLevel warn
                CustomLog ${APACHE_LOG_DIR}/access.log combined
    

    </VirtualHost>

    init.py

    from flask import Flask

    app = Flask(name)

    @app.route('/')

    @app.route('/flaskapp/')

    def homepage():
    return "Hi there, how are you?"

    if name == "main":
    app.run()

    resh@metis:/var/www/FlaskApp/FlaskApp$ pwd
    /var/www/FlaskApp/FlaskApp
    resh@metis:/var/www/FlaskApp/FlaskApp$ ls
    init.py init.py~ static templates venv
    resh@metis:/var/www/FlaskApp/FlaskApp$

Be the first one to answer this question.