apache 配置

一般 配置:

Directory:

<Directory /usr/local/httpd/htdocs>
Options Indexes FollowSymLinks
</Directory>

封装一组指令,使之仅对文件空间中的某个目录及其子目录生效

使用<Location>来将指令应用于独立于文件系统之外的内容。文件系统之内的内容请使用<Directory><Files>指令。

SetHandler

<Location /status>
SetHandler server-status
</Location>

强制所有匹配的文件被一个指定的处理器处理。

AddHandler

AddHandler python-program .py

强制所有匹配的文件被一个指定的处理器处理。

SetEnv:

SetEnv env-variable value

设置环境变量。

关于 .htaccess文件

这个文件是一个配置文件。不过它位于程序文件目录。

记得有个apache模块有个 mod_rewrite.so 他的作用就是改变路由。开启这个模块,在.htaccsess下就可以重写URL。

实战:(配置mod_python虚拟主机)

   1,配置apache

    进入 /etc/apache2/site-available

    $ a2enmod rewrite  # URL重写

    $ cp default django

    $ sudo vim django   

 1 <VirtualHost *:80>
 2         ServerAdmin webmaster@localhost
 3         ServerName Django
 4         DocumentRoot /var/www
 5         <Directory />
 6                 Options FollowSymLinks
 7                 AllowOverride All
 8         </Directory>
 9         <Directory /var/www/django>
10                 Options Indexes FollowSymLinks MultiViews
11 
12                 SetHandler python-program
13                 PythonHandler django.core.handlers.modpython
14                 setEnv DJANGO_SETTINGS_MODULE mysite.setting
15                 PythonDebug ON
16 
17                 AllowOverride All
18                 Order allow,deny
19                 allow from all
20         </Directory>
21 
22         ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
23         <Directory "/usr/lib/cgi-bin">
24                 AllowOverride None
25                 Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
26                 Order allow,deny
27                 Allow from all
28         </Directory>
29 
30         ErrorLog ${APACHE_LOG_DIR}/py.error.log
31 
32         # Possible values include: debug, info, notice, warn, error, crit,
33         # alert, emerg.
34         LogLevel warn
35 
36         CustomLog ${APACHE_LOG_DIR}/py.log combined
37 
38     Alias /doc/ "/usr/share/doc/"
39     <Directory "/usr/share/doc/">
40         Options Indexes MultiViews FollowSymLinks
41         AllowOverride None
42         Order deny,allow
43         Deny from all
44         Allow from 127.0.0.0/255.0.0.0 ::1/128
45     </Directory>
46 
47 </VirtualHost>
View Code

    $ a2ensite django

   2,写入hots

    $ vim /etc/hosts

    >> 127.0.0.1 django

   3,建立django项目

    进入 /var/www

    $ django-admin.py startproject blog

   4,

        

 

  

原文地址:https://www.cnblogs.com/canbefree/p/3791505.html