首頁  >  文章  >  運維  >  linux下apache設定檔在哪裡

linux下apache設定檔在哪裡

藏色散人
藏色散人原創
2019-07-03 11:25:0110320瀏覽

linux下apache設定檔在哪裡

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下建立一個指向某個虛擬主機設定檔的連結時,就啟用了它;如果要關閉某個虛擬主機的話,只需刪除對應的連結即可,根本不用去改設定檔。

sudo cp /etc/apache2/sites-avaliable/000-default.conf , 命名为 test.conf

2.修改設定檔:test.conf


# 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

    Options FollowSymLinks
    DirectoryIndex index.php index.html index.htm
    AllowOverride All #注意这个地方的配置,会影响本地目录下的.htaccess的启用
    Order deny,allow
    Allow from All

# 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

建立連結檔:

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使用教學欄位!

以上是linux下apache設定檔在哪裡的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn