linux apache 配置

區(qū)別于Windows 下Apache,配置文件通常只有一個,就是httpd.conf。

本機環(huán)境是通過

apt-get install xxx

Linux下 Apache的配置文件是 /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下建立一個指向某個虛擬主機配置文件的鏈 接時,就啟用了它;如果要關(guān)閉某個虛擬主機的話,只需刪除相應(yīng)的鏈接即可,根本不用去改配置文件。

  1. 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'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>
  1. 建立鏈接文件:
sudo ln -s /etc/apache2/sites-available/test.conf /etc/apache2/sites-enabled/test.conf

或者: sudo a2ensite test.conf

4.重啟apache 服務(wù)器

sudo /etc/init.d/apache2 restart
  1. 修改hosts(/etc/hosts)
// 增加一行
127.0.0.1 www.test.com

到這里基本就可正常訪問了!

附:如果這里還需要對目錄級的URL重寫支持,繼續(xù)往下:

  1. 終端運行
sudo a2enmod

程序提示可供激活的模塊名稱,輸入:rewrite

成功會提示

rewrite already load
  1. 修改/etc/apache2/sites-enabled/test.conf (該鏈接指向的是站點配置文件)
    把下的AllowOverride 屬性改為All,保存。(上面我們已經(jīng)配置為 All)

  2. 重新加載apache

sudo /etc/init.d/apache2 restart
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,555評論 19 139
  • 一、Nagios簡介 Nagios是一款開源的電腦系統(tǒng)和網(wǎng)絡(luò)監(jiān)視工具,能有效監(jiān)控Windows、Linux和Uni...
    1b3bd36d9d21閱讀 8,395評論 3 13
  • Apache 與 Tomcat 配置 Apache 配置(Linux) 安裝sudo apt-get instal...
    wswenyue閱讀 4,322評論 0 7
  • 在Windows下,Apache的配置文件通常只有一個,就是httpd.conf。但我在Ubuntu Linux上...
    dongshixiao閱讀 950評論 0 1
  • 《大學(xué)》三綱八目,闡明儒家內(nèi)圣外王之徑。三綱挈領(lǐng),八目為法。八目之始,唯在格致;八目之終,唯在治平。故曰格...
    梅篆儒閱讀 1,227評論 2 0

友情鏈接更多精彩內(nèi)容