apache2.4配置

注册apache2.4为系统服务

切换到bin目录下,运行   httpd -k install

注销系统服务

切换到bin目录下,运行httpd -k uninstall

命令行运行

切换到bin目录下,运行  httpd -t 

1、解压版。

解压至相应目录。

2、修改conf目录下httpd.conf文件

3、修改38、39行

Define SRVROOT "d:/Apache24"

ServerRoot "d:/apache24"

4、修改监听端口,60行

Listen 80

5、去掉所有proxy注释

6、修改ServerAdmin,215行

ServerAdmin admin@sjy.net.cn

7、修改servername ,224行

ServerName www.sjy.net.cn:80

8、修改SRVROOT,248、249行

DocumentRoot "${SRVROOT}/htdocs"
<Directory "${SRVROOT}/htdocs">

DocumentRoot "d:/apache24/htdocs"

<Directory "d:/apache24/htdocs">

9、修改    ScriptAlias /cgi-bin/ "${SRVROOT}/cgi-bin/"  365行

ScriptAlias /cgi-bin/ "d:/apache24/cgi-bin/"

10、利用命令行运行的方式,根据提示,放开权限,去掉注释。

httpd-vhosts.conf配置

1、<VirtualHost _default_:80>

DocumentRoot "d:/apache24/htdocs"

2、<VirtualHost *:80>
        ServerName xxx.xxx.gov.cn
        ServerAlias www.xxx.net.cn
        DocumentRoot "D:/webroot/andacms/export/sjzedu"
<Directory />
AllowOverride none
Require all granted
</Directory>



        ErrorDocument 404 /index.html
        ErrorDocument 403 /index.html


        ProxyPass /edu http://xxx.xxx.xxx.xxx/edu
        ProxyPassReverse /edu http://xxx.xxx.xxx.xxx/edu


        ProxyPass /report_sjy http://xxx.xxx.xxx.xxx:9002/report_sjy
        ProxyPassReverse /report_sjy http://xxx.xxx.xxx.xxx:9002/report_sjy


        ProxyPass /dynamic http://127.0.0.1:8080/andacms/export/sjzedu/dynamic
        ProxyPassReverse /dynamic http://127.0.0.1:8080/andacms/export/sjzedu/dynamic


        DirectoryIndex index.html
</VirtualHost>


Apache HTTP服务器通过其强大的模块化设计支持虚拟主机配置,允许在同一台物理机器上托管多个网站或Web应用程序。对于Apache 2.4版本来说,设置虚拟主机涉及编辑`httpd.conf`文件(Windows环境下)或者是位于`/etc/apache2/sites-available/`目录下的`.conf`文件(Linux环境中)。以下是针对Apache 2.4的基本步骤指南: ### 步骤一:启用必要的模块 首先确认已启用了处理名称为基础的虚拟主机所需的模块——namely `mod_rewrite` 和 `vhost_alias`. ```bash a2enmod rewrite vhost_alias ``` 然后重启Apache服务使更改生效。 ### 步骤二:创建站点配置文件 每个虚拟主机应该拥有独立的配置文件;例如我们要添加名为example.com的新虚拟主机,则应在`sites-available`下新建一个叫做`example.com.conf`的文本档,并加入下面内容作为示例: #### 对于HTTP (端口80): ```apache <VirtualHost *:80> ServerAdmin webmaster@example.com DocumentRoot "/var/www/html/example" ServerName example.com ServerAlias www.example.com <Directory /var/www/html/example/> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> ``` 请注意将路径、域名等信息替换为你自己的实际值. ### 步骤三:激活新配置并测试 当完成上述所有操作之后,请记得运行命令来启用新的虚拟主机: ```bash a2ensite example.com.conf # 替换为您的配置文件名 systemctl reload apache2 # 或 service apache2 reload 如果不是systemd系统 ``` 最后一步非常重要 - 检查语法错误: ```bash apachectl configtest ``` 如果一切正常的话,你应该能够访问到刚刚建立好的虚拟主机组件了! --
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值