App not responding after flask application Apache deployment(mod_wsgi) - apache

I'm trying to deploy my flask application on Apache web server using mod_wsgi.
After the deployment, when i go to the 'healthCheck' URL i configured to return a simple text message, the app is not responding and it's timing out.
This is my wsgi file:
<VirtualHost *:5000>
ServerName <My ip address here>
ServerAdmin admin#mywebsite.com
WSGIScriptAlias / /var/www/ReleaseServices/ReleaseServices.wsgi
<Directory /var/www/ReleaseServices/ReleaseServices/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/ReleaseServices/ReleaseServices/static
<Directory /var/www/ReleaseServices/ReleaseServices/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I don't see any error in the apache logs as well. What could be the issue?
Please ask me if any extra details are required.

So i found the solution after searching a lot.
I was using scikit-learn in my init.py script and the import statement was causing issues and making the app unresponsive. After removing the import, it was working fine.
When i searched for solutions, i found some interesting facts related to the WSGI configuration, one of which i had missed out:
http://blog.rtwilson.com/how-to-fix-flask-wsgi-webapp-hanging-when-importing-a-module-such-as-numpy-or-matplotlib/
In that link, check the comment by Graham Dumpleton:
The specific solution is forcing use of the main interpreter by setting the application group to %{GLOBAL}. It is documented in
http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Python_Simplified_GIL_State_API
Basically you have to add the following line to your .wsgi file:
WSGIApplicationGroup %{GLOBAL}
This will force a specific WSGI application to be run within the very first Python sub interpreter created when Python is initialised and hence solves the problem!

Related

Apache2 fails to find the requested URL when accessed via a domain name, but functions perfectly via an IP address?

I've recently been migrating a small website on a VPS from a rudimentary and static one to the Flask framework, via WSGI/Apache2. However, while access to the website is functional when accessing from a browser using the IP address, use of the domain name brings the standard and nonspecific Apache2 message "The requested URL was not found on this server." My VHost is as follows:
<VirtualHost *:443>
ServerName slow.estate
ServerAlias www.slow.estate
ServerAdmin my.email#gmail.com
WSGIScriptAlias / /var/www/se/se.wsgi
<Directory /var/www/se/se/>
Order allow,deny
Require all granted
</Directory>
Alias /static /var/www/se/se/static
<Directory /var/www/se/se/static/>
Order allow,deny
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I've tried this both with the VHost set to port 80 (and, of course, with SSLify disabled) and with SSL and port 443, with no difference. The problem also persists no matter if I use Apache's older Allow from all or the newer Require all granted in my VHost. In the VHost above, the website will not work at all. If I modify the ServerName to be the IP address, then it works exclusively when that IP address is entered into the browser. Each time I try and fail to use the website in the above manner, a relevant entry is made in access.log, and no entry is made in error.log.
I've only found one other person out there with a similar problem to me, and that seemed just to be that their nonstandard TLD was being misinterpreted by their browser, which is why I mention that my TLD is .estate. I doubt, surely, that this could be the issue, especially when this issue, unlike the other person's, plagues me across browsers?

Apache showing empty "index of /", after dist upgrade

I'm working on a Debian 7 server which I did a dist upgrade on so it is Debian 8 now.
The only thing I am having trouble with is the apache2 which got updated from 2.2 to 2.4. the problem that is that now it shows me an empty "Index of /" although there are a lot of files in the specified folders.
vHost Conf:
<VirtualHost *:80>
ServerAdmin some#email
ServerName some.server
ServerAlias some.server
DocumentRoot "/data/apt/public_html"
<Directory "/data/apt/public_html">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Require all granted
</Directory>
</VirtualHost>
How can I get it working again?
mixing 2.2 and 2.4 access directives is not recommended. Look at http://httpd.apache.org/docs/current/upgrading.html. You will see that they never mix Order allow,deny with Require all granted. So remove your Order line.
Mixing old and new directives
Mixing old directives like Order, Allow or Deny with new ones like
Require is technically possible but discouraged. mod_access_compat was
created to support configurations containing only old directives to
facilitate the 2.4 upgrade. Please check the examples below to get a
better idea about issues that might arise.
Also, you do not specify a DocumentIndex file so Apache does not know which file it should return a client when he asks for http://some.server/.
Let's assume the default page is index.html, add this in your VirtualHost:
DocumentIndex index.html
Note 1: ServerAlias has the same value as ServerName, and is therefore not required.
Note 2: you should setup access and error log files for this VirtualHost. It might not be useful if you have only 1 VirtualHost, but you will thank me if you have a large site (with multiple VH later).

How to access multiple copies of wsgi site on server

I have a Flask web site providing a service on an apache server, and now would like to run another copy of the code base for testing purposes on the same server (a different svn branch). So, I've installed the codebase in a different place on the server, and added another WSGIScriptAlias entry, referencing the test codebase, to the apache conf file:
# Entry point for the user web interface:
WSGIScriptAlias /mysite /blah/blah/wsgi_entry.py
# Entry point for the test branch of the user web interface:
WSGIScriptAlias /mysiteTEST /blah/blah/testBranch/wsgi_entry.py
I was hoping that sending the browser to "mysiteTEST" instead of the usual "mysite" would have me running the code in the test branch. However it runs the original code, presumably because the wsgi_entry.py simply does something like:
from my_main_module import app as application
and where it's looking for my_main_module is presumably the python path set in the apache config, like so:
WSGIPythonPath /blah/blah/main_code_place
Which is correct for the main site, but I want to mysiteTEST to be running the modules in the test branch location. So perhaps I can override the python path somehow in the testBranch/wsgi_entry.py (and perhaps not?), but is there a simpler way that I can manage this in the apache config? I.e. can I somehow specify one WSGIPythonPath for /mysite, and another for /mysiteTEST?
Set up multiple virtualhosts:
<VirtualHost your.ip:80>
ServerName blahblah
ServerAdmin blahblah#blah.com
WSGIDaemonProcess blahblah user=b group=lah threads=5
WSGIScriptAlias /mysite /blah/blah/wsgi_entry.py
<Directory /blah/blah>
Options Indexes FollowSymLinks Includes ExecCGI
WSGIScriptReloading On
WSGIProcessGroup blahblah
WSGIApplicationGroup %{GLOBAL}
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost your.ip:80>
ServerName blahblahTEST
ServerAdmin blahblah#blah.com
WSGIDaemonProcess blahblahtest user=b group=lah threads=5
WSGIScriptAlias /mysiteTEST /blah/blah/testBranch/wsgi_entry.py
<Directory /blah/blah/testBranch>
Options Indexes FollowSymLinks Includes ExecCGI
WSGIScriptReloading On
WSGIProcessGroup blahblah
WSGIApplicationGroup %{GLOBAL}
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I ended up solving this by adding a single line to modify the path in the wsgi entry point for the alternate code version (i.e. the file referenced in the apache config line "WSGIScriptAlias /mysiteTEST /blah/blah/testBranch/wsgi_entry.py" in my example). The line overrides the wsgi configured python search path. Not the apache config only solution I wanted, but it's only a single line addition and it does the job:
import sys
sys.path.insert(0, '<path for alternate code modules>')
from my_main_module import app as application

Apache VirtualHost Loading the Wrong Page

Problems
An Apache VirtualHost keeps loading the wrong directory when I'm telling it to load a completely different part. Here is what I have for the VirtualHost:
<VirtualHost *:80>
DocumentRoot "/Workspace/Font"
ServerName fonts.wrks.tk
# ErrorLog "/Logs/Workarea/Fonts/Error.log"
# CustomLog "/Logs/Workarea/Fonts/Access.log" common
<Directory "/Workspace/Font">
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
So, the problem, I'm telling it to load /Workspace/Font But it's not, it's loading /Workspace instead. I'm not sure how this came to be.
Attempt at Solution
There's not much I could do considering that the search on Google gave me no relevant results on what I was trying to fix. But regardless, here is some things I did myself to try and fix it.
Restarted Apache Multiple times
Changed permissions around:
sudo chown -R daemon:daemon /Workspace/Fonts (I run XAMPP, and the user and group is daemon)
Checked Error Logs (Nothing Relevant to the problem was printed)
Created a index folder and/or tried to access folder and files within the domain.
It turns out I didn't have the VirtualHosts line uncommented, thanks for anyone that helped in the past. But everything works now.

Magento not accessible since tried to move to multi website setup. Apache issue?

I wish I had never seen this article:
http://www.magentocommerce.com/knowledge-base/entry/tutorial-multi-site-multi-domain-setup
I have Apache 2.2 installed on my XP machine and until a while ago I had a Magento site that I could test the development of a custom module on. I decided that I wanted to have multiple websites and multiple stores so that I could test that my modules configuration variables set at the different scopes (global, website, and store) were working as expected.
So I followed the instructions in the above Magento article. I created a website and gave it a name of “paulsplace.com”. I created a couple of Stores under that website. I then went to System/Configuration/General/Web and, with the scope set to paulsplace.com, I set the unsecured and secured URLs to http://paulsplace.com/ and https://paulsplace.com/ and hit Save Config - what a mistake!!
I got a 404 error. And now I can’t get to my magento front end or back end.
I tried a couple of things:
I added these lines to my hosts lookup file:
127.0.0.1 paulsplace.com
127.0.0.1 www.paulsplace.com
I then uncommented this line in my httpd,conf file:
Include conf/extra/httpd-hosts.conf
and added the following to the conf/extra/httpd-hosts.conf file:
<VirtualHost *:80>
ServerAdmin me#myemail.com
DocumentRoot "C:/Applications/Apache Software Foundation/Apache2.2/htdocs"
ServerName paulsplace.com
ErrorLog "logs/paulsplace.com-error.log"
CustomLog "logs/paulsplace.com-access.log" common
</VirtualHost>
and restarted Apache.
If I browse to “http://www.paulsplace.com” I now get a page that just says “It works!”. Same for “http://paulsplace.com” and “http://www.paulsplace.com/magento/index.php”.
I tried a few more things - I added this line to httpd.conf:
AccessFileName htaccess
(I did this because Windows Explorer didn’t let me create a file starting with a dot; I could do it from the command prompt, but I believe what I have done should be ok).
I changed AllowOverride to All from None:
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
<Directory "C:/Applications/Apache Software Foundation/Apache2.2/htdocs">
AllowOverride All
</Directory>
and in C:\Applications\Apache Software Foundation\Apache2.2\htdocs\htaccess (a file that I created), I entered:
SetEnvIf Host www\.paulsplace\.com MAGE_RUN_CODE=pws1
SetEnvIf Host www\.paulsplace\.com MAGE_RUN_TYPE=website
SetEnvIf Host ^paulsplace\.com MAGE_RUN_CODE=pws1
SetEnvIf Host ^paulsplace\.com MAGE_RUN_TYPE=website
(pws was the value I used for the “Code” when creating my store).
Please tell me how I can put this right. I feel like I’m taking one step forward and three backward at the moment.
Any help really would be greatly appreciated.
<VirtualHost *:80>
ServerAdmin me#myemail.com
DocumentRoot "Change this to point at your magento install"
ServerName paulsplace.com
ErrorLog "logs/paulsplace.com-error.log"
CustomLog "logs/paulsplace.com-access.log" common
SetEnv MAGE_RUN_TYPE website
SetEnv MAGE_RUN_CODE pws1
</VirtualHost>
If changing anything in System Configuration borks your system, you can always clear out the bad values in the database directly, and clear your Magento cache. Do a
select * from core_config_data where value LIKE '%paulsplace.com%'
This will give you the two rows that were added when you clicked save. Remove the rows. Next, clear out all the files in
var/cache/*
to clear your cache. Then restore your Apache config to what it was before you started monkeying around. This should restore your site back to its previous state, and you can continue to experiment with things.