寫個總結筆記,讓以後的自己知道怎麼部署。 首先apache的版本是2.4.7,然後系統是Ubuntu 14.04.1 LTS。(因為好像配置文件和目錄有差異) 首先進到apache2目錄下, 我們要探討的主要是sites available和sites enabled根據字面意思,前一個是網站可用的 ...
寫個總結筆記,讓以後的自己知道怎麼部署。
首先apache的版本是2.4.7,然後系統是Ubuntu 14.04.1 LTS。(因為好像配置文件和目錄有差異)
首先進到apache2目錄下,
我們要探討的主要是sites-available和sites-enabled根據字面意思,前一個是網站可用的,後一個是網站可用的,然後我們還知道了,sites-enabled裡面的文件是sites-available裡面文件的軟鏈接,所以我們主要改site-available的文件,打開site-available有兩個文件,但我們只需要000-default.conf文件,打開cat文件,代碼如下:
<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 seothert it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/
# 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
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# 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>
這就是網址配置文件了,而我們要修改的只有被註釋掉的ServerName 功能變數名稱,DocumentRoot 路徑這兩個部分,去掉註釋剩下。
<VirtualHost *:80>
ServerName #這裡是功能變數名稱地址
ServerAdmin webmaster@localhost
DocumentRoot /var/www/ #這裡是路徑
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
可以直接添加在下麵,重啟apache就成了。但是上面的優先順序要更高,訪問自己的功能變數名稱會跳轉到你設置的路徑,直接訪問ip還是會到第一個設置的路徑,你也可以選擇刪除。
還有另外一種改法就是新建一個文件,xxx.conf然後內容一樣,
<VirtualHost *:80>
ServerName #這裡是功能變數名稱地址
ServerAdmin webmaster@localhost
DocumentRoot /var/www/ #這裡是路徑
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
在創建軟鏈接 ln -s ../sites-avaiable/xxx.conf ../sites-enable/xxx.conf
這樣子也可以實現,但是優先順序還是000-default.conf高。
好了,就是這麼簡單。