Hey All,
Here is a couple of configurations for reference. First of all, I'd like
to mention we auto-generate these config files using ConfStruct, a config
generator tool. It will spit out production/preview/development configs
with no source code changes. It is not needed but just makes life easier.
Second, I'm not sure how Django/flask/whatever handle loading of code,
etc... But it should be easy to adapt.
Thirdly, if you use a decent linux distribution, this is all super easy via
packages (We use RHEL/Centos6). All I can say is if you can use prebuilt
packages for apache, modwsgi, python, nginx, etc... it saves you a lot of
time and effort.
*______________________________________________________________________________________________________________*
*Nginx per-site config:*
server
{
listen 192.168.50.12:80;
listen 192.168.50.12:443 ssl;
#This is a development URL
server_name admin--daashub--com--jason.step.appcove.net;
#We use self-signed SSL for development
ssl_certificate ssl/WILDCARD.step.appcove.net.crt;
ssl_certificate_key ssl/WILDCARD.step.appcove.net.key;
#nginx uses http/1.0 for proxying, so we need to add some header variables
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Scheme $scheme;
client_max_body_size 1000m;
#Our framework (AppStruct) does have python in the web directory, this
forbids it
location ~ \.(py|pyc|pyo|wsgi)$
{
return 403;
}
#Anything with a .jpg, .css, .js, .whatever, gets served directly by nginx
location ~ \.([a-zA-Z0-9])+$
{
#Web/Main is the document root for this project
root /home/jason/DevLevel.2/DaaS-Installation/DaaS/Hub/Web/Main;
#In production this is set to simply
#expires max;
#In development, it is set to not cache
add_header Cache-Control 'no-cache, no-store, max-age=0,
must-revalidate';
add_header Expires 'Thu, 01 Jan 1970 00:00:01 GMT';
}
#ALL OTHER requests are proxied to apache on 127.0.0.1
:<some-port-for-this-app>
location /
{
add_header Cache-Control 'no-cache, no-store, max-age=0,
must-revalidate';
add_header Expires 'Thu, 01 Jan 1970 00:00:01 GMT';
proxy_pass http://127.0.0.1:60811;
}
}
*______________________________________________________________________________________________________________*
*Apache Global Config:*
#This is in /etc/httpd/conf.d/modwsgi.conf
<IfModule !wsgi_module>
LoadModule wsgi_module modules/mod_wsgi_python3.5.so
WSGISocketPrefix run/wsgi
WSGIApplicationGroup %{GLOBAL}
</IfModule>
*______________________________________________________________________________________________________________*
*Apache per-site config:*
#================================================================================================
# Background Processing
#Apache ONLY listens on localhost and specific non-80 port numbers
Listen 127.0.0.1:60810
#This is a background process for async stuff (like cron, but runs under
the apache application server)
<VirtualHost 127.0.0.1:60810>
ServerName _default_;
#Notice the consistent use of 60810 throughout this section
WSGIDaemonProcess async-60810 processes=1 threads=1
python-path=/home/jason/DevLevel.2/DaaS-Installation/DaaS/Hub/Python
display-name=async-60810
WSGIImportScript
/home/jason/DevLevel.2/DaaS-Installation/DaaS/Hub/Async/wsgi_import_script.wsgi
process-group=async-60810 application-group=%{GLOBAL}
#This might be different in production, but in development, it's great
because the log file is right there in the project to touch and tail
ErrorLog
/home/jason/DevLevel.2/DaaS-Installation/DaaS/Hub/apache-error.log
</VirtualHost>
#================================================================================================
# Main
#This is the actual application
#NOTICE the inclusion of the python path here, this is what makes it all
work
#That directory has all packages needed for the app, or symlinks as needed.
WSGIDaemonProcess Port60811 processes=2 threads=1
python-path=/home/jason/DevLevel.2/DaaS-Installation/DaaS/Hub/Python
Listen 127.0.0.1:60811
NameVirtualHost 127.0.0.1:60811
#Using another port number...
<VirtualHost 127.0.0.1:60811>
ServerName _default_
DocumentRoot /home/jason/DevLevel.2/DaaS-Installation/DaaS/Hub/Web/Main
AddDefaultCharset UTF-8
RewriteEngine on
RewriteOptions inherit
#Forbid any python source files from being served.
RewriteRule \.(py|pyc|pyo|wsgi)$ - [F]
#Everything is passed to modwsgi because nginx already took care of the
other stuff
WSGIScriptAlias /
/home/jason/DevLevel.2/DaaS-Installation/DaaS/Hub/Web/Main/__init__.wsgi
WSGIProcessGroup Port60811
LogLevel info
ErrorLog
/home/jason/DevLevel.2/DaaS-Installation/DaaS/Run/Hub.httpd-error.log
</VirtualHost>
*One other thing:*
because our apache log file is called apache-error.log, we also use this
alias on linux:
alias W='if [ -x ./reload ]; then ./reload; else find ./ -name "*.wsgi" |
xargs touch && tail -f apache-error.log --lines=0; fi;'
It checks for a ./reload script, and if found, calls it. Otherwise it will
touch any *.wsgi files and then re-tail the apache-error.log. It makes
reloading super easy.
[jason@step Hub]$ W
[Mon Oct 03 13:27:17 2016] [info] [client 192.168.50.242] mod_wsgi
(pid=26322): Force restart of process 'Port60811'.
[Mon Oct 03 13:27:17 2016] [info] [client 192.168.50.242] mod_wsgi
(pid=19214): Connect after WSGI daemon process restart, attempt #1.
[Mon Oct 03 13:27:17 2016] [info] [client 192.168.50.242] mod_wsgi
(pid=26323): Force restart of process 'Port60811'.
[Mon Oct 03 13:27:17 2016] [info] [client 192.168.50.242] mod_wsgi
(pid=19214): Connect after WSGI daemon process restart, attempt #2.
[Mon Oct 03 13:27:18 2016] [info] [client 192.168.50.242] mod_wsgi
(pid=26346, process='Port60811', application=''): Loading WSGI script
'/home/jason/DevLevel.2/DaaS-Installation/DaaS/Hub/Web/Main/__init__.wsgi'.
[Mon Oct 03 13:27:19 2016] [error] [client 192.168.50.242]
PointHandlerStart:0867242204b3 ProxySSL:True; URI:/home
[Mon Oct 03 13:27:19 2016] [error] [client 192.168.50.242]
FOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
[Mon Oct 03 13:27:19 2016] [error] [client 192.168.50.242] False
[Mon Oct 03 13:27:19 2016] [error] [client 192.168.50.242]
PointHandlerEnd:0867242204b3:Header=[('Set-Cookie',
'SessionToken=0867242204b3cb4fc49b9589621005a7e3c886cf3d23cdaee5c2304699621554;
expires=Thu, 01-Oct-2026 17:27:19 GMT; Max-Age=315360000; Path=/')]
On Mon, Oct 3, 2016 at 12:27 PM, Scott D Anderson <
[email protected]> wrote:
>
> On Mon, Oct 3, 2016 at 12:40 AM, Jason Garber <[email protected]> wrote:
>
>> If you configure nginx to serve anything ending in .*, and proxy the rest
>> to apache, then apache becomes your app server and nginx becomes your
>> webserver and everything flows. I can provide sample configurations if
>> desired.
>>
>
> I've never worked with nginx, but you are obviously a fan. I'd be
> interested in those sample configurations. I assume nginx runs on port 80
> and Apache on some other port? (I did something like this when I used the
> varnish cache daemon, but I ultimately abandoned it because it didn't seem
> to be buying me much.)
>
> Scott
>
> --
> Scott D. Anderson
> Computer Science Department
> Wellesley College
> [email protected]
> [email protected]
>
>
>
--
You received this message because you are subscribed to the Google Groups
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.