I'm using apache with mod_wsgi, and when I start apache and make a request, I see it make one invokation of the application. After a few minutes (the application gets reloaded), and now I see it make two invokations of the application per request. Why's that?
Also: is there any easy way to initialize resources (database pools, for example) with wsgi? I have the feeling it's complicated...
Here's my conf:
NameVirtualHost *:80
WSGIPythonPath /Users/blahblah/servercode/
WSGIPythonEggs /Users/blahblah/running/eggs/
<VirtualHost *:80>
ErrorLog /Users/blahblah/running/error.log
LogLevel debug
CustomLog /Users/blahblah/running/access.log combined
ServerSignature On
DocumentRoot /Users/blahblah/wsgi
WSGIScriptAlias /mps.py /Users/blahblah/wsgi/wsgi_connector.wsgi
<Directory /Users/blahblah/wsgi>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Related
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>
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()
Is this the correct way to do it? It is better to use subdomains or different domains with the same ip? Thanks in advance.
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>
Then:
sudo systemctl reload apache2
And now I can have my flask app in:
miservidor.com/musicdownloader
I am trying to serve one flask app directly at localhost, and another at localhost/menus.
When my apache configuration is like this:
<VirtualHost *:80>
ServerName localhost
# logs configuration -------------------------------------------------
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# front page ---------------------------------------------------------
WSGIDaemonProcess flask_ac user=#1000 group=#1000 threads=5
WSGIScriptAlias /front /var/www/flask_ac/hookup.wsgi
<Directory /var/www/flask_ac>
WSGIProcessGroup flask_ac
WSGIApplicationGroup flask_ac
Require all granted
</Directory>
# start menus --------------------------------------------------------
WSGIDaemonProcess menus user=#1000 group=#1000 threads=5
WSGIScriptAlias /menus /var/www/flask_ac/projects/menus/hookup.wsgi
<Directory "/var/www/flask_ac/projects/menus/">
WSGIProcessGroup menus
WSGIApplicationGroup menus
Require all granted
</Directory>
It works fine, but it is serving the first app at localhost/front instead of just localhost.
If I change my first WSGIScriptAlias to:
WSGIScriptAlias / /var/www/flask_ac/hookup.wsgi
It will serve the first app correctly at localhost, but the second app at localhost/menus breaks, and returns not found.
I found this answer about a similar issue, but it doesn't address this directly, and I cant seem to figure it out.
Change the order such that the application for the sub URL is first.
WSGIScriptAlias /menus /var/www/flask_ac/projects/menus/hookup.wsgi
...
WSGIScriptAlias / /var/www/flask_ac/hookup.wsgi
Documentation mentioning ordering at:
http://modwsgi.readthedocs.io/en/develop/user-guides/configuration-guidelines.html#the-wsgiscriptalias-directive
After I set the variable SERVER_NAME to be able to use subdomains with blueprints, all pages that before worked with www. as well does not work anymore.
I set
SERVER_NAME = mydomain.com
my apache sites-available conf files looks like this
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
ServerAdmin email#mydomain.com
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
WSGIApplicationGroup %{GLOBAL}
<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp/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 subdomain.mydomain.com
ServerAdmin email#mydomain.com
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
WSGIApplicationGroup %{GLOBAL}
<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
Is there a proper way of fixing this, or is the only way some redirects?
Have to added A record for www.
If not please add the same:
goto : DNS -> SELECT DOMAIN -> ADD RECORD -> Select record type "A"
hostname : www
IP Adress : {Your Public IP}
I've setup the Kilo in LAN, which can't be accessed by the external network. Now, I'd like to do a forwarding to make it be accessed from outside. How to set the ProxyPass and ProxyPassReverse?
I asked this because for Kilo dashboard, the login decorator will redirect http://host.ip/dashboard --> http://host.ip/dashboard/auth/login/?next=/dashboard/. And as a result, the access via forwarding will fail.
Can anyone help?
P.S. (apache configuration)
# ************************************
# Vhost template in module puppetlabs-apache
# Managed by Puppet
# ************************************
<VirtualHost *:80>
ServerName xxx.xxx.com
## Vhost docroot
DocumentRoot "/var/www/"
## Alias declarations for resources outside the DocumentRoot
Alias /dashboard/static "/usr/share/openstack-dashboard/static"
## Directories, there should at least be a declaration for /var/www/
<Directory "/var/www/">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
## Logging
ErrorLog "/var/log/httpd/horizon_error.log"
ServerSignature Off
CustomLog "/var/log/httpd/horizon_access.log" combined
## RedirectMatch rules
RedirectMatch permanent ^/$ /dashboard
## Server aliases
ServerAlias 10.xxx.xxx.xxx
ServerAlias xxx.xxx.com
ServerAlias localhost
WSGIDaemonProcess dashboard group=apache processes=3 threads=10 user=apache
WSGIProcessGroup dashboard
WSGIScriptAlias /dashboard "/usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi"
</VirtualHost>
The issue is now fixed. And it works now. The solution is:
add the external domain name http://external.domain.name/ to virtualHost configuration as a serverAlias as shown below:
ServerAlias external.domain.name
Please your help to know what is wrong with my configuration Apache + Web.py + Mod_WSGI and my website cannot be loaded, this is my config:
Apache version: 2.7.4
Web.py version -> https://github.com/webpy/webpy
mod_wsgi -> not sure if 3.3 or 3.4
Directory
/var/www/pyapps/bot
web -> link webpy
webpy
code.py
static
templates
Apache
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
CustomLog ${APACHE_LOG_DIR}/access.log combine
WSGIScriptAlias /sitea /var/www/pyapps/bot/code.py/
Alias /sitea/static /var/www/pyapps/bot/static
Alias /sitea/templates /var/www/pyapps/bot/templates
AddType text/html .py
<Directory /var/www/pyapps/bot>
Order deny,allow
Allow from All
</Directory>
<Directory /sitea/static>
Options +Indexes
</Directory>
Code.py
import web
urls = (
'/.*', 'hello',
)
class hello:
def GET(self):
return "Hello, world."
application = web.application(urls, globals()).wsgifunc()
Result
Not Found
The requested URL /sitea was not found on this server.
Apache/2.2.22 (Ubuntu) Server at xxx.xxx.xxx.xxx Port 80
You shouldn't have a trailing slash on the end of the WSGIScriptAlias path:
WSGIScriptAlias /sitea /var/www/pyapps/bot/code.py
Also note you shouldn't really have your WSGI application files inside the document root (/var/www). Put them somewhere else (and change the WSGIScriptAlias path accordingly).