Apache下配置Python虚拟服务器

发布时间:2020-05-06编辑:脚本学堂
Apache下配置Python虚拟服务器

因为一直接是用php做开发的,所以采用apache+mod_python+mysql_python。
 

复制代码 代码如下:

NameVirtualHost *:8080
<VirtualHost *:8080>
        ServerName www.investigation.com
        Serveralias investigation
        DocumentRoot "D:/Project/sinotrac/investigation"

        <directory "D:/Project/sinotrac/investigation">
AllowOverride None
                Options Indexes FollowSymLinks
                Order allow,deny
                Allow from all
        </directory>

        <Location "/">
                SetHandler python-program
                PythonPath "['D:/Project/sinotrac'] + sys.path"
                PythonHandler django.core.handlers.modpython
                SetEnv DJANGO_SETTINGS_MODULE investigation.settings
                PythonOption django.root /investigation
                PythonDebug On
        </Location>

        Alias /site_media "D:/Project/sinotrac/investigation/media"

        Alias /media "C:/Python25/Lib/site-packages/django/contrib/admin/media"

        <Directory "C:/Python25/Lib/site-packages/django/contrib/admin/media/">
            Order deny,allow
            Allow from all
        </Directory>

        <Location "/media">
            SetHandler None
        </Location>

        <Location "/site_media">
            SetHandler None
        </Location>

        <Location "/admin_media">
            SetHandler None
        </Location>

#        <LocationMatch ".(jpg|gif|png|css|js)$">
#            SetHandler None
#        </LocationMatch>
</VirtualHost>

我没有用django框架了,所以做了个简单配置:
 

复制代码 代码如下:

<VirtualHost 192.168.1.47>
    ServerName py.ww.com
    DocumentRoot F:Python
    <Directory "F:Python">
        #AddHandler mod_python .py
        SetHandler mod_python
        PythonHandler mod_python.publisher
        PythonDebug On

        Options FollowSymLinks
        AllowOverride FileInfo
    </Directory>

    <Files ~ ".(gif|html|jpg|png)$">
        SetHandler default-handler
    </Files>
</VirtualHost>

在根目录下新建index.py:
 

复制代码 代码如下:

#coding:gb2312
def index(req):
req.write("This is the Index!")
return

def hello(req):
req.write("hello!!!")
return

def get(req,name=""):
if name:
req.write("参数:"+name);
else:
req.write("no param.");
return