登录  /  注册
首页 > 运维 > Apache > 正文

linux下apache配置文件在哪里

藏色散人
发布: 2019-07-03 11:25:01
原创
10203人浏览过

linux下apache配置文件在哪里

linuxapache的配置文件是 /etc/apache2/apache2.conf,apache在启动时会自动读取这个文件的配置信息。而其他的一些配置文件,如 httpd.conf等,则是通过include指令包含进来。

在apache2.conf里有sites-enabled目录,而在 /etc/apache2下还有一个sites-available目录,其实,这里面才是真正的配置文件,而sites- enabled目录存放的只是一些指向这里的文件的符号链接,你可以用ls /etc/apache2/sites-enabled/来证实一下。

所以,如果apache上配置了多个虚拟主机,每个虚拟主机的配置文件都放在 sites-available下,那么对于虚拟主机的停用、启用就非常方便了:当在sites-enabled下建立一个指向某个虚拟主机配置文件的链 接时,就启用了它;如果要关闭某个虚拟主机的话,只需删除相应的链接即可,根本不用去改配置文件。

sudo cp /etc/apache2/sites-avaliable/000-default.conf , 命名为 test.conf
登录后复制

2.修改配置文件:test.conf

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request&#39;s Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName www.test.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/test/
ErrorLog /var/www/html/test/error.log
CustomLog /var/www/html/test/access.log combined
<Directory "/var/www/html/test">
    Options FollowSymLinks
    DirectoryIndex index.php index.html index.htm
    AllowOverride All #注意这个地方的配置,会影响本地目录下的.htaccess的启用
    Order deny,allow
    Allow from All
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
登录后复制

建立链接文件:

sudo ln -s /etc/apache2/sites-available/test.conf /etc/apache2/sites-enabled/test.conf
登录后复制

或者: sudo a2ensite test.conf

4.重启apache 服务器

sudo /etc/init.d/apache2 restart
登录后复制
登录后复制

修改hosts(/etc/hosts)

// 增加一行
127.0.0.1 www.test.com
登录后复制

到这里基本就可正常访问了!

附:如果这里还需要对目录级的URL重写支持,继续往下:

终端运行

sudo a2enmod
登录后复制

程序提示可供激活的模块名称,输入:rewrite

成功会提示

rewrite already load
登录后复制

修改/etc/apache2/sites-enabled/test.conf (该链接指向的是站点配置文件)

把下的AllowOverride 属性改为All,保存。(上面我们已经配置为 All)

重新加载apache

sudo /etc/init.d/apache2 restart
登录后复制
登录后复制

更多Apache相关知识,请访问Apache使用教程栏目!

以上就是linuxapache配置文件在哪里的详细内容,更多请关注php中文网其它相关文章!

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
关于CSS思维导图的课件在哪? 课件
凡人来自于2024-04-16 10:10:18
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号