年年有"余"

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2136|回复: 0

[CentOS] CentOS 添加虚拟主机VirtualHost及伪静态Rewrite

[复制链接]
  • TA的每日心情
    倒霉
    2020-11-28 20:31
  • 签到天数: 18 天

    [LV.4]偶尔看看III

    发表于 2015-10-12 09:03:09 | 显示全部楼层 |阅读模式
    1、找到Apache的配置文件 /etc/httpd/conf/httpd.conf

    2、找到配置文件中的以下代码

    LoadModule vhost_alias_module modules/mod_vhost_alias.so

    如果前面有#号注释,去掉#号注释,这代表是否开启虚拟主机服务

    3、找到配置文件中的以下代码,一般在配置文件的最末尾部分
    #
    # Use name-based virtual hosting.
    #
    #NameVirtualHost *:80
    #
    # NOTE: NameVirtualHost cannot be used without a port specifier
    # (e.g. :80) if mod_ssl is being used, due to the nature of the
    # SSL protocol.
    #

    #
    # VirtualHost example:
    # Almost any Apache directive may go into a VirtualHost container.
    # The first VirtualHost section is used for requests without a known
    # server name.
    #
    #<VirtualHost *:80>
    #    ServerAdmin [email protected]
    #    DocumentRoot /www/docs/dummy-host.example.com
    #    ServerName dummy-host.example.com
    #    ErrorLog logs/dummy-host.example.com-error_log
    #    CustomLog logs/dummy-host.example.com-access_log common
    #</VirtualHost>

    需要用到的部分有
    #########################################################
    #NameVirtualHost *:80

    #<VirtualHost *:80>
    #    ServerAdmin [email protected]
    #    DocumentRoot /www/docs/dummy-host.example.com
    #    ServerName dummy-host.example.com
    #    ErrorLog logs/dummy-host.example.com-error_log
    #    CustomLog logs/dummy-host.example.com-access_log common
    #</VirtualHost>
    #########################################################
    把前面的#去掉或者按照这个格式写一份
    ServerAdmin                // 网站用于接收信息邮箱地址,非必填
    DocumentRoot        // 网站文件所在的绝对路径,相对于服务器的根,不是Apache的根,必填!
    ServerName                // 数据请求的域名,实现同一台服务器,同一个Apache服务,不同域名跳转到不同网站,必填!
    ErrorLog                        // 日志文件,非必填
    CustomLog                // 日志文件,非必填

    4、如果有伪静态,如Discuz的伪静态
    [HTML] 纯文本查看 复制代码
            <IfModule mod_rewrite.c>
                    RewriteEngine On
                    RewriteCond %{QUERY_STRING} ^(.*)$
                    RewriteRule ^(.*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2&%1
                    RewriteCond %{QUERY_STRING} ^(.*)$
                    RewriteRule ^(.*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3&%1
                    RewriteCond %{QUERY_STRING} ^(.*)$
                    RewriteRule ^(.*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3&%1
                    RewriteCond %{QUERY_STRING} ^(.*)$
                    RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page\%3D$4&page=$3&%1
                    RewriteCond %{QUERY_STRING} ^(.*)$
                    RewriteRule ^(.*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3&%1
                    RewriteCond %{QUERY_STRING} ^(.*)$
                    RewriteRule ^(.*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3&%1
                    RewriteCond %{QUERY_STRING} ^(.*)$
                    RewriteRule ^(.*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3&%1
                    RewriteCond %{QUERY_STRING} ^(.*)$
                    RewriteRule ^(.*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3&%1
                    RewriteCond %{QUERY_STRING} ^(.*)$
                    RewriteRule ^(.*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3&%1
            </IfModule>

    应该加在VirtualHost作用域内
    <VirtualHost *:80>
    // 伪静态代码
    </VirtualHost>




    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    手机版|小黑屋|Archiver|iOS开发笔记 ( 湘ICP备14010846号 )

    GMT+8, 2024-3-29 14:18 , Processed in 0.053089 second(s), 22 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表