mod_wsgi keeps restarting flask app [duplicate] - apache

This question already has an answer here:
Why not generate the secret key every time Flask starts?
(1 answer)
Closed 5 years ago.
From Flask's documentation, I have the following in my config:
<VirtualHost *>
ServerName example.com
WSGIDaemonProcess yourapplication user=user1 group=group1 threads=5
WSGIScriptAlias / /var/www/yourapplication/yourapplication.wsgi
<Directory /var/www/yourapplication>
WSGIProcessGroup yourapplication
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
In my .wsgi file, I import the proper python file and import the flask app as application. Everything works fine, but I added logging to that file because I suspected something was wrong. Apparently, that wsgi file gets called every so often whenever a browser makes connection. It restarts the app (or at least a new process). I never noticed this, nor did I see it as a problem until I imported flask-login to manage authenticated sessions. Now whenever I login, after some short time, the wsgi app is reloaded and the session history no longer exists. In effect, I have to login every few seconds. Is this the intended way mod_wsgi works? I've tested my flask app running in standalone mode (flask's own devel server) and it works flawlessly.
In a way it's a duplicate, but it's also not. The server code isn't buggy. It's just mod_wsgi restarts the application over and over. Thanks for linking to the other post, though!

So what I found is that wsgi does restart the application every so often. I suppose this is expected behavior, but it's not what I expected. My issue with getting logged out was caused because I generate the app's secret key on startup. Therefore, the secret key was being changed constantly. Obviously this invalidates the cookies and logs a user out. So, I guess if you want to generate a secret key and not just have plain text in your source, you need to generate it once externally and import it into your flask application so that it doesn't always change.

Related

Unable to hit https for certain projects

I have a project in xampp/htdocs/project1
I needed to create another project so I decided to assign them different ports so now,
xampp/htdocs/project1 runs on 8080
and my project2 which is under
C:/release/project2 runs on 7171
I needed to make project2 https , so created ssl certificate and everything is setup in apache too.(listening to 443)
https:/xx.xx.xx.xxx:443/project1/login.php gave error
whereas https:/xx.xx.xx.xxx:443/project2/login.php could be hit.
so i did following change in httpd-ssl.conf,
DocumentRoot "C:/xampp/htdocs" to DocumentRoot "C:/release"
but now i get the error -
Access forbidden!
You don't have permission to access the requested object. It is either
read-protected or not readable by the server.
If you think this is a server error, please contact the webmaster.
Error 403
This error is given for both,
https:/xx.xx.xx.xxx:443/project1/login.php
and https:/xx.xx.xx.xxx:443/project2/login.php
I thought it was permission problems, but i can still hit these
https:/xx.xx.xx.xxx:8080/project1/login.php
and https:/xx.xx.xx.xxx:7171/project2/login.php
What could be the problem? I am new to website development so could not figure out what I am doing wrong.Is project being under htdocs compulsory for this or assigning of different ports was wrong?
You might have got it working by now,
But It seems like the permissions are not set.
It is not compulsary to have the project under htdocs.Since your project is working on 7171 everything might be fine.
you can try following,
1) for permissions, Check if you have AllowOverride All Order allow,deny Allow from all set in httpd.conf too.Restart the server.
If it still doesnt work,
2) check if http://www.youtube.com/watch?v=ZUAKLUZa-AU can help.

What is the easiest way to run a local server of a website built using ColdFusion with Coldspring, Reacter, and Model-Glue?

Here is the situation: I was given a machine with a subversioned repository of an old website to update/add contents every now and then. The website is built using ColdFusion and Model-Glue MVC, AND I have no idea (zero) about ColdFusion. The other website we run is on CakePHP and that is good enough learning curve for me. ;(
With that said, I don't have a problem modifying it's contents because its all HTML and javascript. The problem is that with each minor change, I have to commit to the development repository on the server THEN go online to see how the change looks like!
It gets very frustrating just to try different values for a simple thing like the "height" attribute of an html tag!! And what frustrated me even more is trying to run a local copy on my machine for that repository!
What I tried so far:
I installed CF10 with WAMP.
Configured vhosts file for the new server.
Added my user to ColdFusion Application server service (windows 7x64)
But whenever I try to open it in the browser it gives me "Exception Service Error Application Exception"!! Any help please?
**Update: I forgot to ask! how to know the index.cfm file that the website starts with? For example, I know in CakePHP its app/webroot/index.php. What is that in (Coldfusion X Model-Glue)? there are so many index.cfm and application.cfm files!
my httpd-vhosts.conf block about this server is like the following:
<VirtualHost *>
ServerName localhost-CF
DocumentRoot "C:/wamp/www/my/webroot/directory/"
<Directory "C:/wamp/www/my/webroot/directory/">
Options Indexes FollowSymLinks Includes ExecCGI
allow from all
order allow,deny
# Enables .htaccess files for this site
AllowOverride All
</Directory>
# Apache will look for these two files, in this order, if no file is specified in the URL
DirectoryIndex index.cfm index.html index.php
</VirtualHost>
Here is a link to a Screen Cap --no enough rep ;{ -- of what I get using both servers (not at the same time though) apache and built-in:
CF10 Local Server Setup Issue
Also, here is a block from cfusion\logs\application.log:
"Error","ajp-bio-8012-exec-1","08/15/13","10:34:38","PREK","Error during init: Could not find the ColdFusion component or interface coldspring.beans.DefaultXmlBeanFactory. Ensure that the name is correct and that the component or interface exists."
"Error","ajp-bio-8012-exec-1","08/15/13","10:34:38","PREK","Error during exception service init: Element EXCEPTIONSERVICE is undefined in a Java object of type class [Ljava.lang.String;. "
"Error","ajp-bio-8012-exec-1","08/15/13","10:34:38","PREK","Error during application init: The datasource named cfclientstorage is not a valid client storage DSN. Define client storage DSN through the ColdFusion Administrator."
I do have cfclientstorage as a DSN storage and the Administrator tells me its verified!
However, I think, if this exact repository works fine on the server then I should not worry about the code! it most likely a system/server configuration or installation problem (on my local machine).
It looks like you're using ColdSpring. You need to login into ColdFusion Administrator and add a mapping to your ColdSpring directory for example:
/coldspring --> c:/ColdSpring
Also you will need to set a datasource to point to your "cfclientstorage" database. This is also in ColdFusion Administrator

Apache not allowing access to sub directories

I installed Apache2, php, and mysql onto my Linux Mint machine with the hopes of continuing a website I had built. After copy and pasting all of the code I had I noticed a problem with one of my include statments:
<?php include("./dir/file1.html");
That wasn't working. Originally I thought the issue was with php but after a lot of trial and error I've concluded it's apache not allowing access to subdirectories in the /var/www/ directory.
Since I'm new to editing apache configuration files, I'm not really sure what to change to allow access to all subdirectories within /var/www/ on localhost. I've tried adding:
<Directory /var/www/*>
order allow,deny
allow from all
</Directory>
to my httpd.conf file (which was blank, which I learned had something to do with Linux Mint being Debian based) and confirmed that default in /sites-available had similar code. I'll post that if it's requested.
I'm unsure on what else I can do to get apache to allow access to subdirectories in my /var/www/ directory for localhost and none of my previous methods have worked.
UPDATE:
I believe it's an Apache issue because when trying to go to a subdirectory through the browser (like localhost/dir/), I get a 403 error. I don't have to be going to an actual webpage for that problem. Also, include statments including files in the current directory has no problem, only with subdirectories.
The Include statement above gives no errors or any other useful messages. Whatever the include statement is including is just not there. I've tried require but that gives me a 500 server error: the server may be down for maintenance (paraphrased).

Broken links in local Wordpress site

I have a wordpress site set up on a live server, and I have replicated the site locally by following these steps:
FTPed live files to local
Set up virtual host (dev.domain.com) to point at local version of site
Imported the db locally
changed wp-config.php to the correct local db settings
changed 'home' and siteurl' in db.wp_options to point to http://dev.domain.com (from http://www.domain.com)
Home page loads fine, /wp-admin all loads fine.
Problem is in links to pages:
Permalinks are set to point to post name: http://dev.example.com/sample-post/, just as on live server. However, locally, all links to posts are broken, and Apache (2.2.17) is responding with the following error: "The requested URL /sample-post/ was not found on this server."
I'm assuming I've missed a configuration step somewhere, though I've followed this process umpteen times in the past with no problems. The issue with this particular site is that the theme has been hacked with lots and lots of absolute paths entered, meaning setting up a dev site has required loads of code changes.
I'm not really sure how to further trouble shoot this, not completely understanding how Wordpress / Apache handles permalinks
Copy the .htaccess if you haven't already
I think that might be the problem
OK - sorted this, it was to do with mod_rewrite on apache.
To fix (this is for my install of Ubuntu 11.04):
first enable mod_rewrite in apache
sudo a2enmod rewrite
Then edit the relevant file in /etc/apache2/sites-available (could be 'default', or one specific to site):
sudo vi /etc/apache2/sites-available/site-file
Change AllowOverride directive for your site document root from None to All:
:
<Directory /var/www/site.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
That seems to have done it.

mod_wsgi and Django app periodically hang

I've got a large Django app. It has two Apache virtual hosts pointing to different settings files, so part of the application is accessible via one URL, and part via another. The Django app uses virtualenv.
mod_wsgi is configured to run in daemon mode with the following in Apache's VirtualHost block:
# domain 1:
WSGIDaemonProcess fc processes=5 threads=5 display-name=%{GROUP} \
user=nobody group=nobody
WSGIScriptAlias / /var/www/python/mine/apache/my.wsgi \
process-group=fc application-group=%{GROUP}
# different apache.conf file for domain 2:
WSGIDaemonProcess fm processes=5 threads=5 display-name=%{GROUP} \
user=nobody group=nobody
WSGIScriptAlias / /var/www/python/mine/apache/other.wsgi \
process-group=fm application-group=%{GROUP}
Every now and again while using the sites, a request will hang. It never completes. I have to use the browser's 'refresh' button to reload the page, and then the request normally works.
Apache itself runs in prefork mode and MaxRequestsPerChild is set to 0 because I've read that could be a problem. This happens often enough for it to be a potential problem - every 100 requests perhaps, something like that.
Has anyone got any idea why this is happening?
Thanks
That should be 'application-group=%{GLOBAL}' for WSGIDaemonProcess options, not '%{GROUP}'. The '%{GLOBAL}' is special and means the main Python interpreter. Using the main interpreter often gets around problems with third party C extension modules for Python which don't work in sub interpreters, including experiencing deadlocks. The '%{GROUP}' value is only relevant to the 'display-name' option.