Windows + Apache + mod_proxy

912 views
Skip to first unread message

Omi Chiba

unread,
Oct 4, 2011, 11:51:02 AM10/4/11
to web2py-users
Is anybody running web2py with this configuration ? If so, can you
share the instruction and/or apache configuration ?

web2py dirctory: C:\web2py
App: http://localhost:8000/welcome

Currently, my web2py site is running on

- Ubuntu + Apache + wsgi
- Windows + Apache + wsgi

but because of the issues below, I cannot use pyodbc to connect
msssql. So I was forced to use mysql.

pyodbc

Issue (Linux) http://code.google.com/p/pyodbc/issues/detail?id=169
Issue (Windows) http://code.google.com/p/pyodbc/issues/detail?id=126&q=wsgi

Paolo Caruccio

unread,
Oct 6, 2011, 7:47:59 PM10/6/11
to web2py-users
The following istructions have been adapted from
http://jdoe.asidev.com/2009/02/26/configure-web2py-to-run-behind-apache-with-wsgi-mod_wsgi/
for my dev enviroment Windows + Apache + mod_wsgi.
I succesfully tested connection to db2 express from IMB through
pyodbc. Maybe it could help you.
I premise that I'm not a programmer and computer development is an
hobby for me, so my support will be very poor.
Below enviroment has been used for development only, not in
production.

PREREQUISITES: python 2.7 installed on Windows

STEP A - webserver preparation [http://sourceforge.net/projects/
miniserver/files/Uniform%20Server/7.1.11-Orion/]
a1 - download and install uniformserver;
a2 - after installation, access to the server administrator panel and
"SECURE" all entries in the "Server Security" page;
a3 - generate a new SSL certificate by "Tools > Server Key & Cert Gen"
link on right sidebar;
a4 - create a certificate signed by our CA using UniServer_CA_1.0
plugin [http://sourceforge.net/projects/miniserver/files/Plugins/
UniServer_CA/];
a5 - replace the files created in the a3 step in X:\UniServer\usr\local
\apache2\conf folder ( X is the drive where uniformserver has been
installed );
a6 - install new certificate in Trusted Certification Authorities.
Usually I put ca.crt file in main folder of my website, start the
server, and by browser go to http://localhost/ca.crt
( replace localhost with website name to simulate real situation )
and install the certificate following browser instructions;
a7 - start the server and check that https pages are accessible
without certificate errors.
Notes: when upgrade the server simply copy in their folders on the new
server the SSL files created in the previous version of the server

STEP B - mod_wsgi [http://code.google.com/p/modwsgi/wiki/
DownloadTheSoftware?tm=2]
b1 - download Windows binary selecting the correct one for the version
of Python and Apache that is being used ( I use mod_wsgi-win32-
ap22py27-3.3.so - Apache 2.2 / Python 2.7 );
b2 - stop UniServer, rename downloaded file in "mod_wsgi.so" and put
it in X:\UniServer\usr\local\apache2\modules folder ( X is the drive
where uniformserver has been installed );
b3 - add to X:\UniServer\usr\local\apache2\conf\httpd.conf file
following row: "LoadModule wsgi_module modules/mod_wsgi.so"( without
quotation marks );
b4 - restart UniServer and check that mod_wsgi is succesfully
installed.
Notes: when upgrade the server repeat the step B

STEP C - web2py (for sure you know where download it)
c1 - download web2py source code and unzip it in X:\UniServer\www
folder ( X is the drive where uniformserver has been installed );
c2 - stop UniServer, start web2py server in standard way by double
clicking X:\UniServer\www\web2py\web2py.py in order that it create its
own files (don't change default settings);
c3 - stop web2py server and check that in web2py folder there are
"options_std.py" e "parameters_8000.py";
c4 - open options_std.py and make sure of row "password = '<recycle>'"
is present;
c5 - create following symlinks (only in windows7 by "mklink" command
or using "Symlink Creator" [http://code.google.com/p/symlinker/
downloads/list]):
1) options_std.py -> options.py
2) parameters_8000.py -> parameters_80.py
3) parameters_8000.py -> parameters_443.py
Notes: in windowsXP copy files listed above on the left and rename
them with the names on the right.
When upgrade web2py, rename or delete previous web2py folder, but
in the latter case make sure of backup your web2py apps.

STEP D - apache vhost file
d1 - stop UniServer, create a new "vhost_web2py.conf" file in X:
\UniServer\usr\local\apache2\conf folder ( X is the drive where
uniformserver has been installed ) with following content :

##########VIRTUAL HOST SETUP##########
# WEB2PY.LOCALHOST
<VirtualHost ****LIP****:80>
ServerName ****SVN****:80
DocumentRoot ****DIR****/www/web2py
WSGIScriptAlias / ****DIR****/www/web2py/wsgihandler.py
ServerAdmin ****EMAIL****
# static files do not need WSGI
<LocationMatch "^(/[\w_]*/static/.*)">
Order Allow,Deny
Allow from all
</LocationMatch>
# everything else goes to web2py via wsgi
<Location "/">
Order deny,allow
Allow from all
</Location>
# Log. Can be disabled
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogLevel notice
CustomLog ****DIR****/tmp/web2py.access.log common
ErrorLog ****DIR****/tmp/web2py.error.log
</VirtualHost>
#------------------------------------------------------------
<VirtualHost ****LIP****:443>
ServerName ****SVN****:443
ServerAdmin ****EMAIL****
DocumentRoot ****DIR****/www/web2py
WSGIScriptAlias / ****DIR****/www/web2py/wsgihandler.py
# static files do not need WSGI
<LocationMatch "^(/[\w_]*/static/.*)">
Order Allow,Deny
Allow from all
</LocationMatch>
<Location "/">
Order deny,allow
Allow from all
</Location>
<Directory "****DIR****/www/web2py">
Order allow,deny
Deny from all
</Directory>
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogLevel notice
CustomLog ****DIR****/tmp/web2py.access.log common
ErrorLog ****DIR****/tmp/web2py.error.log
SSLEngine on
SSLProtocol -all +TLSv1 +SSLv3
SSLCipherSuite HIGH:MEDIUM:!aNULL:+SHA1:+MD5:+HIGH:+MEDIUM
SSLCertificateFile ****DIR****/usr/local/apache2/conf/ssl.crt/
web2py.crt
SSLCertificateKeyFile ****DIR****/usr/local/apache2/conf/ssl.key/
web2py.key
SetEnvIf User-Agent ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
</VirtualHost>
##########END VIRTUAL HOST SETUP##########

IMPORTANT NOTES:
replace in above code
****LIP**** with real IP i.e. 192.168.1.114 for LAN or
208.67.220.222 for WAN
****SVN**** with your server name i.e. web2py.localhost
****DIR**** with X:/UniServer ( X is the drive where uniformserver
has been installed )
****EMAIL**** with your email i.e. ad...@smtp.net
modify paths in line with your preferences

d2 - at the end of X:\UniServer\usr\local\apache2\conf\httpd.conf file
add "Include conf/vhost_web2py.conf";
d3 - create, like in step A, the SSL certificate and key for the
servername (i.e. web2py.localhost). Note that SSL permits only one
certificate for each IP;
d4 - open "%WINDOWS%\system32\drivers\etc\hosts" file and add the
alias "127.0.0.1 web2py.localhost". Replace server's IP to 127.0.0.1
and access to web2py from not localhost;
d5 - start UniServer, now you can access to web2py inserting
"web2py.localhost" in address bar of your browser.
Notes: when upgrade UniServer, repeat only d2 and copy the old files
in the upgraded server.

Final notes related to pyodbc (attention!only connection and basic
insert tested):
- pyodbc ( pyodbc-2.1.11.win32-py2.7.exe ) installed
- driver odbc activated in windows control panel
- DAL connection string = 'db2://
DSN=databasename;UID=userid;PWD=password'

Ciao.

On 4 Ott, 17:51, Omi Chiba <ochib...@gmail.com> wrote:
> Is anybody running web2py with this configuration  ? If so, can you
> share the instruction and/or apache configuration ?
>
> web2py dirctory: C:\web2py
> App:http://localhost:8000/welcome
>
> Currently, my web2py site is running on
>
> - Ubuntu + Apache + wsgi
> - Windows + Apache + wsgi
>
> but because of the issues below, I cannot use pyodbc to connect
> msssql. So I was forced to use mysql.
>
> pyodbc
>
> Issue (Linux)http://code.google.com/p/pyodbc/issues/detail?id=169
> Issue (Windows)  http://code.google.com/p/pyodbc/issues/detail?id=126&q=wsgi

Omi Chiba

unread,
Oct 7, 2011, 3:31:03 PM10/7/11
to web2py-users
Paolo,

You gave me a hope because it looks you tried it recently and it's
very similar to my environment. (Is your OS Windows 7, XP, or Windows
Server ??)

My environment:
OS: Windows 7 SP1 - 32bit
Python: 2.7.2
Apache: httpd-2.2.21-win32-x86-openssl-0.9.8r.msi
mod_wsgi: mod_wsgi-win32-ap22py27-3.3.so
pyodbc: pyodbc-2.1.11.win32-py2.7.exe
pywin32: pywin32-216.win32-py2.7.exe

I was keep thinking what makes the difference. I know you use Uniform
Server but
the version of apache included is the same as mine. So it should be
the same.

Only possible difference is an apache config, The below is the part of
httpd.conf let me know if you find anything wrong. It's running fine
except pyodbc cannot make connection to mssql/db2 under wsgi but it
does connect under Rocket server and console.

=================================
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/web2py/applications"
ServerName ochba-183

<Directory "C:/web2py">
Order allow,deny
Deny from all
</Directory>

<Location "/">
Order deny,allow
Allow from all
</Location>

<LocationMatch "^(/[\w_]*/static/.*)">
Order Allow,Deny
Allow from all
</LocationMatch>

WSGIScriptAlias / "C:/web2py/wsgihandler.py"

</VirtualHost>

NameVirtualHost *:443
<VirtualHost *:443>
DocumentRoot "C:/web2py/applications"
ServerName ochiba-183

<Directory "C:/web2py">
Order allow,deny
Deny from all
</Directory>

<Location "/">
Order deny,allow
Allow from all
</Location>

<LocationMatch "^(/[\w_]*/static/.*)">
Order Allow,Deny
Allow from all
</LocationMatch>

WSGIScriptAlias / "C:/web2py/wsgihandler.py"

SSLEngine On
SSLCertificateFile conf/server.crt
SSLCertificateKeyFile conf/server.key

</VirtualHost>
============================
On Oct 6, 6:47 pm, Paolo Caruccio <paolo.carucci...@gmail.com> wrote:
> The following istructions have been adapted fromhttp://jdoe.asidev.com/2009/02/26/configure-web2py-to-run-behind-apac...
> for my dev enviroment Windows + Apache + mod_wsgi.
> I  succesfully tested connection to db2 express from IMB through
> pyodbc. Maybe it could help you.
> I premise that I'm not a programmer and computer development is an
> hobby for me, so my support will be very poor.
> Below enviroment has been used for development only, not in
> production.
>
> PREREQUISITES: python 2.7 installed on Windows
>
> STEP A - webserver preparation [http://sourceforge.net/projects/
> miniserver/files/Uniform%20Server/7.1.11-Orion/]
> a1 - download and install uniformserver;
> a2 - after installation, access to the server administrator panel and
> "SECURE" all entries in the "Server Security" page;
> a3 - generate a new SSL certificate by "Tools > Server Key & Cert Gen"
> link on right sidebar;
> a4 - create a certificate signed by our CA using UniServer_CA_1.0
> plugin [http://sourceforge.net/projects/miniserver/files/Plugins/
> UniServer_CA/];
> a5 - replace the files created in the a3 step in X:\UniServer\usr\local
> \apache2\conf folder ( X is the drive where uniformserver has been
> installed );
> a6 - install new certificate in Trusted Certification Authorities.
> Usually I put ca.crt file in main folder of my website, start the
> server, and by browser go tohttp://localhost/ca.crt

Paolo Caruccio

unread,
Oct 9, 2011, 3:46:04 AM10/9/11
to web2py-users
My enviroment
windows7 64 bit
Apache/2.2.21 (Win32) DAV/2 mod_ssl/2.2.21 OpenSSL/1.0.0e mod_wsgi/3.3
Python/2.7.2 PHP/5.3.8
pywin32-216.win32-py2.7
pyodbc-2.1.11.win32-py2.7
web2py 1.99.2 stable
db2exc_974_WIN_x86_64 - IBM DB2 Express-C

httpd.conf is the same as that one comes with uniform server, I only
added to it two rows:
# to load mod_wsgi
LoadModule wsgi_module modules/mod_wsgi.so
# vhost_web2py is a separated file (see my previous message for its
content)
Include conf/vhost_web2py.conf

so it's simple compare it with your, downloading uniform server (that
is portable and install less)

Regarding db2 driver after I installed IBM DB2 Express-C I made the
following steps:

1) in db2 control center I created a new empty database and named it
"TEST" alias "TEST"
2) activated IBM DB2 ODBC DRIVER :
2a) in win7 control panel > administrative tools > Data Sources
(ODBC)
2b) in opened window > tab "User DSN" > "Add" button
2c) in new popup window select "IBM DB2 ODBC DRIVER" > "End" button
2d) in next window
2d1) Data Name Source = "TEST"
2d2) Database alias = "TEST"
2d3) Pressed OK button

In web2py I created a new simple application and connected to database
through the string:

db = DAL('db2://DSN=TEST;UID=userid;PWD=password')

where userid and password are the same as accessing to IBM DB2 Express-
C.

At the end I succesfully registered a new user, so all worked fine for
me.

Ciao.
Paolo
> >                 ****LIP**** with real IP i.e. 192.168.1.114 for...
>
> leggi tutto

Omi Chiba

unread,
Oct 9, 2011, 11:33:27 AM10/9/11
to web2py-users
Paolo,

Thank you again.

>so it's simple compare it with your, downloading uniform server (that
>is portable and install less)

I will try uniform server next monday and tuesday, then update the
result here.
> > >                    ...
>
> read more »

Omi Chiba

unread,
Oct 10, 2011, 4:51:56 PM10/10/11
to web2py-users
Paolo,

I finished the setting and access http://ochiba-183(My PC Name) but it
shows the default index.php under www and not web2py.

>d4 - open "%WINDOWS%\system32\drivers\etc\hosts" file and add the
>alias "127.0.0.1 web2py.localhost". Replace server's IP to 127.0.0.1
>and access to web2py from not localhost;
>d5 - start UniServer, now you can access to web2py inserting
>"web2py.localhost" in address bar of your browser.

I wasn't sure this part, so I just add "127.0.0.1 ochiba-183" to my
hosts.

Do you know what I'm doing wrong ? The following is my
vhost_web2py.conf which is included by httpd.conf.

##########VIRTUAL HOST SETUP##########
# WEB2PY.LOCALHOST
<VirtualHost 10.30.6.122:80>
ServerName ochiba-183:80
DocumentRoot F:/UniServer/www/web2py
WSGIScriptAlias / F:/UniServer/www/web2py/wsgihandler.py
ServerAdmin ad...@gmail.com
# static files do not need WSGI
<LocationMatch "^(/[\w_]*/static/.*)">
Order Allow,Deny
Allow from all
</LocationMatch>
# everything else goes to web2py via wsgi
<Location "/">
Order deny,allow
Allow from all
</Location>
# Log. Can be disabled
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogLevel notice
CustomLog F:/UniServer/tmp/web2py.access.log common
ErrorLog F:/UniServer/tmp/web2py.error.log
</VirtualHost>
#------------------------------------------------------------
<VirtualHost 10.30.6.122:443>
ServerName ochiba-183:443
ServerAdmin ad...@gmail.com
DocumentRoot F:/UniServer/www/web2py
WSGIScriptAlias / F:/UniServer/www/web2py/wsgihandler.py
# static files do not need WSGI
<LocationMatch "^(/[\w_]*/static/.*)">
Order Allow,Deny
Allow from all
</LocationMatch>
<Location "/">
Order deny,allow
Allow from all
</Location>
<Directory "F:/UniServer/www/web2py">
Order allow,deny
Deny from all
</Directory>
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogLevel notice
CustomLog F:/UniServer/tmp/web2py.access.log common
ErrorLog F:/UniServer/tmp/web2py.error.log
SSLEngine on
SSLProtocol -all +TLSv1 +SSLv3
SSLCipherSuite HIGH:MEDIUM:!aNULL:+SHA1:+MD5:+HIGH:+MEDIUM
SSLCertificateFile F:/UniServer/usr/local/apache2/conf/ssl.crt/
server.crt
SSLCertificateKeyFile F:/UniServer/usr/local/apache2/conf/ssl.key/
server.key
SetEnvIf User-Agent ".*MSIE.*" \
#nokeepalive ssl-unclean-shutdown \
#downgrade-1.0 force-response-1.0
</VirtualHost>
##########END VIRTUAL HOST SETUP##########

> > > >                        ...
>
> read more »

Paolo Caruccio

unread,
Oct 10, 2011, 5:20:11 PM10/10/11
to web...@googlegroups.com
Hi Omi,

>I wasn't sure this part, so I just add "127.0.0.1 ochiba-183" to my hosts.

Try to replace with "10.30.6.122 ochiba-183"

Let me know if it works.

Ciao.

Paolo

Omi Chiba

unread,
Oct 10, 2011, 6:28:57 PM10/10/11
to web2py-users
Paolo,

You made my day !! web2py is up and pyodbc works fine under wsgi !!!
Grazie molto!

Paolo Caruccio

unread,
Oct 10, 2011, 6:41:22 PM10/10/11
to web...@googlegroups.com
I am very glad I helped

Ciao.

Paolo

Omi Chiba

unread,
Oct 12, 2011, 1:29:03 PM10/12/11
to web2py-users
Paolo,

I just finished summarized this setting and post on my blog.

http://ochiba77.blogspot.com/2011/10/how-to-setup-web2py-apache-wsgi-uniform.html

Paolo Caruccio

unread,
Oct 12, 2011, 3:14:29 PM10/12/11
to web...@googlegroups.com
Well done!

Paolo

Omi Chiba

unread,
Nov 8, 2011, 10:26:09 AM11/8/11
to web2py-users
Paolo,

People can access the site by server name but not IP.
Do you know how to change the configuration ?

http://ochiba-183/welcome/default/index (OK)
http://10.30.6.122/welcome/default/index (NG)

On Oct 12, 1:14 pm, Paolo Caruccio <paolo.carucci...@gmail.com> wrote:
> Well done!
>
> Paolo

Paolo Caruccio

unread,
Nov 8, 2011, 1:43:22 PM11/8/11
to web...@googlegroups.com
Omi,

please try the following:

in vhost_web2py.conf replace
 
<VirtualHost *:80>
ServerName ochiba-183

with
<VirtualHost LIP:80>
ServerName ochiba-183

where LIP is the server's IP

See for reference my previous post (STEP D)

Let me know if it works.

Paolo

P.S. Moreover what do you think about to change the thread title  to Windows + Apache + mod_wsgi ?

 

Omi Chiba

unread,
Nov 8, 2011, 2:09:34 PM11/8/11
to web2py-users
It worked !!
Thanks again!
Reply all
Reply to author
Forward
0 new messages