Linux apache配置虛擬主機

1.進入/usr/local/apache/conf/httpd.conf,
  註釋掉:DocumentRoot "/usr/local/apache/htdocs",該成:DocumentRoot "/var/www/";
  啓用:Include conf/extra/httpd-vhost.conf;php

2.修改配置文件的的Allowoverride(兩處都修改了)
  http://www.jb51.net/article/30120.htmhtml

3.肯定apache配置文件httpd.conf下安裝了路由重寫模塊並開啓了路由重寫模塊。
 (源碼編譯方式安裝不會自動安裝模塊)。
  文件路徑:usr/local/apache/conf/original/httpd.conf
(路徑:LoadModule rewrite_module modules/mod_rewrite.so)apache

http://gaoxingf.blog.51cto.com/612518/190362/ide

3.虛擬機配置文件添加路由重寫文件
<VirtualHost 123.45.23.76:80>
    ServerAdmin 123.45.23.76
    DocumentRoot "/var/www/gcash"
    ServerName 123.45.23.76
    ErrorLog "logs/dummy-host2.example.com-error.log"
    CustomLog "logs/dummy-host2.example.com-access.log" common
    
    <Directory "/var/www/gcash">
        Options +FollowSymlinks
        RewriteEngine On.net

        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
    </Directory>
    
</VirtualHost>htm

可是配置成上面的形式可能會致使部分的文件沒法解析,即一些能夠訪問,
一些不能訪問,因此,咱們增長解,析配成下面的形式:
<VirtualHost 123.45.23.76:80>
    ServerAdmin 123.45.23.76
    DocumentRoot "/var/www/gcash
    ServerName 123.45.23.76
    ErrorLog "logs/dummy-host2.example.com-error.log"
    CustomLog "logs/dummy-host2.example.com-access.log" commonblog

    DirectoryIndex index.php index.html (新增長的一行)
    
    <Directory "/var/www/gcash">
        Options +FollowSymlinks
        RewriteEngine On路由

        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
    </Directory>
    
</VirtualHost>源碼

相關文章
相關標籤/搜索