When does apache2 execute a .wsgi script when using daemon process groups? - apache2

Given a simple apache2 conf as below, when will django.wsgi execute? It seems like it executes only the first time a query arrives and never again. I was expecting it to execute on apache startup and then never again. Can anybody shed some light on how this works?
WSGIDaemonProcess site-1 user=user-1 group=user-1 threads=25
WSGIProcessGroup site-1
WSGIScriptAlias / /usr/local/django/mysite/apache/django.wsgi
<Directory /usr/local/django/mysite/apache>
Order deny,allow
Allow from all
</Directory>

WSGI script files are technically not executed but are imported. Thus they are like any other module in Python, they are loaded once. In this case it occurs when the request first arrives and the application mapped by that WSGI script file is required.
Once loaded, the WSGI application object is executed once per request.
There are some exceptions to that as far as reloading of the WSGI script file in certain circumstances. For an explanation of that read:
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode
Now although it is loaded the first a request requires it to be, you can force that it be loaded on process startup using the WSGIImportScript directive:
http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIImportScript
or the use of process-group and application-group options together with the WSGIScriptAlias directive. The latter was introduced in mod_wsgi 3.o.
http://code.google.com/p/modwsgi/wiki/ChangesInVersion0300

Related

React.js and folder access denied for user

I don't know if there is any type of post like this one here on StackOverflow but I just wonder how do I make so people who visit my site can't get access to "ip/folder names".
If it for some help I use react.js and I know some people use the .htaccess file but it doesn't work for me or maybe because I do it wrong. I am kind of new of this sort of things.
Error page
I want actually do so if people visit some page/folder or file they come to a page it says "404 page error"
To be able to use .htaccess files depends on how the apache configuration is done on your server. A .htaccess file needs permission to be able to override standard web configurations. If you want to set that up and use them you can try:
sudo vim /etc/apache2/sites-available/default
Then make sure the line AllowOverride has the value All. That means local .htaccees files are allowed to override.
<Directory /var/www/>
...
AllowOverride All
...
</Directory>
Save and restart the service
sudo service apache2 restart
In your .htaccess file you can add following for creating an custom error page
ErrorDocument 404 /my_custom_error_page.html
Here you can read more about writing .htaccess files
https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file
Hope that helped a bit.

Apache localhost authentication

I am trying to setup up basic authentication to a folder on my localhost running apache. Currently the app runs fine without authentication. I have setup a virtual host so I can access my application through dev.myapp.com
The code I add to my .htaccess file to force authentication is:
<Directory "/Users/myusername/Sites/dev.myapp.com">
AuthType Basic
AuthName Test
AuthBasicProvider file
AuthUserFile /etc/apache_users
Require valid-user
</Directory>
I have created a user.
When I type dev.myapp.com into the browser I get an internal server error. I am fairly new to apache. A point in the right direction would be appreciated.
Thanks.
First off, using .htaccess is a bit slower and requires that you have set the AllowOverride directive accordingly. It is recommended that you instead use httpd.conf to establish basic authentication. The Apache documentation explains all of this so check out this link http://httpd.apache.org/docs/2.2/howto/auth.html.
Regardless, I think I see the error. Your <Directory> tag looks a little odd. I understand the name of your site is dev.my.app.com but is that the actual name of the folder where the site dev.myapp.com points to on your server? Your httpd.conf file should have an entry like this:
<VirtualHost *>
DocumentRoot "document/root/path"
Other directives here
</VirtualHost>
The DocumentRoot is where Apache directs all incoming web traffic. If you are trying to establish authentication for your entire site, the value of DocumentRoot is most likely what you would want in your Directory tag ... making it <Directory /document/root/path>.
To locate httpd.conf look in in /etc/apache2/. Make sure to restart your server after you change the file (sudo /etc/init.d/apache2 restart). Hope that helps, please update if you haven't already resolved the problem.

Setup Roundup with WSGI and Apache

I was install Roundup 1.4 by Debian Squeeze official repo and want to run it with my Apache server using mod_wsgi. Host configuration:
<VirtualHost *:80>
ServerName support.domain.com
WSGIScriptAlias / /var/roundup/support/apache/roundup.wsgi
WSGIDaemonProcess support.roundup user=roundup group=roundup threads=25
WSGIProcessGroup support.roundup
<Directory /var/roundup/support>
<Files roundup.wsgi>
Order allow,deny
Allow from all
</Files>
</Directory>
# ... some logging configuration
</VirtualHost>
I was install tracker in /var/roundup/support using roundup-admin install, configure it and next initialise using roundup-admin initialise. Then I was created apache/roundup.wsgi:
from roundup.cgi.wsgi_handler import RequestDispatcher
tracker_home = '/var/roundup/support'
application = RequestDispatcher(tracker_home)
When opening my site at http://support.domain.com (ofcourse this url is bit different) I have HTTP response 500 Internal Server Error and log with:
mod_wsgi (pid=17433): Exception occured processing WSGI script '/var/roundup/support/apache/roundup.wsgi'.
RuntimeError: response has not been started
What's going on? How to run roundup with wsgi (not cgi) properly? Or where to look why response has not been started?
EDIT
Roundup's install manual says that wsgi handler would look like this:
from wsgiref.simple_server import make_server
# obtain the WSGI request dispatcher
from roundup.cgi.wsgi_handler import RequestDispatcher
tracker_home = 'demo'
app = RequestDispatcher(tracker_home)
httpd = make_server('', 8917, app)
httpd.serve_forever()
But this make no response. Browser loading it forever without message or server log. I think starting another server from script running by apache module isn't good idea. So I tried another code sample:
from roundup.cgi.wsgi_handler import RequestDispatcher
tracker_home = '/var/roundup/support'
application = RequestDispatcher(tracker_home)
from flup.server.fcgi import WSGIServer
WSGIServer(application).run()
But this throws some errors like:
WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
There must be a way to run my application from RequestDispatcher...
According to this issue this is an permission's problem. Solved using:
WSGIDaemonProcess support.roundup user=roundup group=roundup threads=25
WSGIProcessGroup support.roundup
where files in /var/roundup/support/ has roundup as owner and group with appropriate access permissions.
Try:
from roundup.cgi.wsgi_handler import RequestDispatcher
tracker_home = '/var/roundup/support'
application = RequestDispatcher(tracker_home)
All mod_wsgi needs is an 'application' object which is a valid WSGI application entry point.
You do not need to start a WSGI server or FASTCGI adapter yourself as you have been trying to do.

Can't access files in a subdirectory using Apache server

I have an Apache 2.2.21 server installed on my Windows 7 machine.
My site is up and my scripts from /scripts subdirectory are working but when I try to load icons from /icons I get a 403 forbidden error.
I've already added this to my httpd.conf file:
<Directory "c:/wamp/www/icons/">
Options Indexes FollowSymLinks
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
Still no effect. So the question is: how can I access files in my /icons subfolder?
P.S.: Using /images subdirectory worked out just fine but the question still remains.
I figured out that /icons/ was included as an alias for some other directory. For me, configuration file was located at:
C:\wamp\bin\apache\apache2.2.21\conf\extra\httpd-autoindex.conf
I had to comment out this line:
Alias /icons/ "c:/Apache22/icons/"
Have you checked the Windows permissions on the /icons directory, and made sure that the Apache user can read that directory? Is there possibly an .htaccess file in the picture?
Edit: Okay, so it's not permissions. My next guess is this: your config above says "everyone is forbidden access except when they're coming from 127.0.0.1". But you're on Windows 7. Windows 7 tries to be helpful and modern - and often tries accessing via IPv6 first. So you might show up as coming from ::1, which is probably failing to match 127.0.0.1. Try turning off IPv6 or adding an Allow from ::1 directive.
Ok so if your httpd.conf doesn't do anyhting you should restart apache. Any changes done to documents have to be restarted so Apache can "Refresh".
<Directory "c:/wamp/www/icons/">
Options Indexes FollowSymLinks
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
So above this is your code. It basically says in line 4 that Apache should deny connection from all incoming connections connections to the /icons/folder.
Also on line 5 it says to allow incoming connections from only 127.0.0.1 or localhost. So basically the server has access to it!
If changing it doesn't work you should look in .htaccess. Another option is just to copy the Code from a folder that works and paste it and just change the paste from EX:
"C:/WAMP/www/images/" to "C:/WAMP/www/icons".

ProxyPassMatch directive problems

We have an environment with Apache 2.2.11 acting as front end to incoming connections to a Tomcat backend server. We are using the following directives in the http-ssl.conf, which works great when not trying to catch 403 errors:
SetEnvIf COMPANY EDLP 4.0.1 NLEDLPKEY=true
General setup for the virtual host
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost:443
ServerAdmin admin#localhost
ProxyRequests Off
ProxyPassMatch / htp://tomcat.company.com**<-- been having issues with this directive (using only one "t" in http to bypass this sites new user can only post one URL per question limitation**
ProxyPassReverse / htp://tomcat.company.com
As you can see we are using the mod_access (now called mod_authz_host in Apache 2.2) module to pass a variable called NLEDLPKEY so that only (Internet Explorer) clients with this variable could access Tomcat via SSL. Also, I am trying to not only reverse proxy SSL connections, but also to redirect the 403 errors (for people without the variable) to a specified page (error_page.html). I have tried:
ProxyPassMatch "^[^(/error_page.html)]" htp://tomcat.company.com and also tried
ProxyPassMatch “^(?!/error_page.html)” htp://tomcat.company.com
to see if it is possible to redirect to the error page and not get the below message:
Forbidden
You don't have permission to access /RDS on this server. <--RDS is just a directory-->
Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.9 Server at apache-company Port 443
Any help would be appreciated
R.
I ran into this issue recently - it took a bit of hunting but here's how I fixed it:
In /etc/apache2/mods-available/proxy.conf (Ubuntu - YMMV) change it to look like the following:
<Proxy *>
AddDefaultCharset off
Order deny,allow
Deny from all
Allow from all
</Proxy>
It's also important to note that for reverse proxies, it is not necessary to have ProxyRequests On configured and doing so in conjunction with Allow from all is hazardous. (Can be used by spammers to send mail via your proxy.)

Resources