Ubuntu14.04下Apache2+mod_jk+tomcat 配置Tomcat服務器集羣負載均衡

最近研究tomcat負載均衡,在網上查了很多資料感覺都不太全,好不容易自己研究出來了。想寫一篇完整的搭建教程,一方面方便以後查閱,另一方便也分享給需要的人。我這個人有個毛病,一般對網上寫的東西都不放心,所以還是要親力親爲:)
好了廢話少說,開始!

JDK環境變量配置:

vi /etc/profile, 把下面代碼粘在末尾,只需要修改你的JAVA_HOME目錄:

export JAVA_HOME=/usr/lib/jvm/java1.8
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

百度百科小白一下:
首先說一下背景,以下來自於百度百科。mod_jk 簡稱JK,是Apache服務器的一個可插入模塊,用以爲Apache或IIS服務器提供處理JSP/Servlet的能力。Apache作爲一款強大的Web服務器,本身缺乏處理JSP/Servlet的功能,爲了能夠處理對JSP/Servlet的請求,必須使用JSP/Servlet容器,如Tomcat等。Tomcat本身也可以作爲Web服務器使用,但是其功能遠不及Apache強大,所以Tomcat往往作爲JSP/Servlet容器使用。mod_jk實質上是Apache與Tomcat的連接器,並藉此附帶提供集羣和負載均衡的功能。

我的配置環境:兩臺ubuntu server14.04,tomcat8,apache2。

  1. 運行以下兩條命令,安裝apache2和mod_jk.so;
 sudo apt-get install apache2  
 sudo apt-get install libapache2-mod-jk  

安裝完之後,可在/usr/lib/apache2/modules文件夾下看到mod_jk.so文件。
如果遇到安裝錯誤,先運行以下命令即可:

apt-get update
  1. 配置apache.conf文件,在ubuntu 14.04系統中,配置有一些不一樣的地方。在apache2的文件夾下,找不到httpd.conf文件。查看apache2.conf文件,發現文件中有這樣的兩行代碼,在/etc/apache2/mod-enabled文件夾下,看到了jk.conf和jk.load文件,因此,配置mod_jk可在這兩個文件裏進行。
/etc/apache2/apache2.conf

裏面可以發現如下配置:

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

3.打開jk.conf文件,添加如下代碼,增加服務器的安全性。

//把原來的註釋去掉即可
JkOptions +RejectUnsafeURI

然後再添加如下的代碼,使Apache可以轉發請求到我們設置的worker上。
重點內容,經過測試,這塊不配置也可以,主要是後面的/etc/apache2/sites-available/000-default.conf

JkMount /* loadbalancer

4.配置work.properties文件
在jk.conf文件中,我們可以看到如下一行代碼,這說明workers.properties文件放在了/etc/libapache2-mod-jk/workers.properties文件下,當然你也可以更改這個路徑,重新建立一個worker.properties。但是爲了簡便,可以直接到這個路徑下修改workers.properties。

JkWorkersFile /etc/libapache2-mod-jk/workers.properties  

5.下面針對每一tomcat worker做一下配置,如下所示。這裏port是8009,它是tomcat默認的AJP13協議的監聽端口,可在Tomcat的context.xml中修改這個端口。host是遠程tomcat的地址可帶上端口號,host可以是主機名也可以是IP地址。type是我們使用的apache和tomcat的通信協議,這裏是ajp13。lbfactor是用於負載均衡的權值,值越大那麼apache就認爲這個服務器的性能越好,那麼就會將更多的請求發送給這個Tomcat服務器。socket_timeout是如果tomcat在這個時間內沒有迴應JK時,JK就會生成一個錯誤,然後進行重試,如果不設置這個值,默認情況下,JK會一直等待。socket_keepalive設置爲True是防止防火牆將JK和Tomcat之間閒置的連接切斷。ping_mode指示在什麼時候進行連接偵測,即檢查JK和Tomcat的連接是否正常,它有很多檢測的模式,這裏我使用的是I,然後再給出一個探測的超時時間ping_timeout,那麼當連接空閒時間超過connection_ping_interval時,JK就會去檢測連接是否正常,connection_ping_interval的默認時間是(ping_timeout/1000)*10。
下面貼出我的配置(兩臺Ubuntu虛擬機,一個tomcat在本機):

worker.list=loadbalancer,tomcat1,tomcat2

#
#------ ajp13_worker WORKER DEFINITION ------------------------------
#---------------------------------------------------------------------
#

#
# Defining a worker named ajp13_worker and of type ajp13
# Note that the name and the type do not have to match.
#
#============tomcat1==============
worker.tomcat1.port=8009
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1

#=============tomcat2=============
worker.tomcat2.port=8009
worker.tomcat2.host=10.134.0.88
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1
#
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=tomcat1,tomcat2
worker.loadbalancer.sticky_session=1

如果要共享session,必須將sticky_session=1

5.在work.properties文件中配置負載均衡worke

這個負責負載均衡的worker是一個虛擬的worker,它並不直接與Tomcat服務器進行交流,但它卻管理着其它worker,負責負載均衡。在worker.properties文件中添加如下兩行。這樣聲明創建一個loadbalance worker,它的類型是lb,負責負載均衡,它管理着namenode和cloud2這兩個worker。其它的配置選項用默認的就好了。

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=tomcat1,tomcat2
worker.loadbalancer.sticky_session=false

6.編輯/etc/apache2/sites-available/000-default.conf文件,在<VirtualHost*:80>中添加如下代碼。

這塊必須要配置:JkMount /* loadbalancer,否則過濾出現問題

<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.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        # 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
        JkMount /* loadbalancer
        # 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>

至此apache就配置完成了。

7.在每個Tomcat節點上進行配置
首先,在標籤中配置jvmRoute屬性,如下所示,注意這個屬性的值要和你的worker的名字一樣。

<Engine name="Catalina" defaultHost="localhost" jvmRoute="cloud2">  

然後,在標籤中添加以下這段代碼。

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>  

Tomcat8/conf/server.xml修改代碼貼出,方便拷貝:
注:我用的垂直測試,就是tomcat在不同機子上,不過水平測試我也會嘗試下:)

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">
      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
      </Host>
     <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
    </Engine>

8.你要部署的項目集羣配置:
(1)修改項目中的WEB-INF/web.xml文件,加入如下行:

<Context distributable="true" />

這裏寫圖片描述
所有需要集羣的web項目,其web.xml中都必須添加
這個定義
(2) 將tlcom分別部署到2個tomcat中:
這裏因爲我沿用原來在tomcat上的開發方式,並不直接把項目放到tomcat/webapp目錄下
(3) 分別啓動兩個tomcat
可以在tomcat\bin目錄下執行
來啓動,也可以通過在eclipse中先將server配置好(配置對應的2個tomcat server),在
eclipse中啓動。
啓動tomcat1:
和正常eclipse中啓動一樣,加載插件:
RONE初始化:
成功啓動:
這裏寫圖片描述
啓動tomcat2:
啓動過程和tomcat1一樣,值得注意的是,在tomcat2啓動的時候,tomcat1會打印出集羣中加入
member的提示:
這裏寫圖片描述

(4) 啓動apache.通過IP訪問apache. 比如我的是 http://10.188.182.43 (這裏80端
口寫不寫是一樣的)。
你會發現可能RONE都登陸不了,或者登陸了頁面都無法正常打開。原因在於我們一開始配置的
Mod_jk.conf文件。文件末尾的請求轉發。我們只轉發了jsp頁面的請求,就是說apache只會把
jsp頁面的請求轉發到2個tomcat上去。因此我們需要修改過濾的規則。我沒有找到資料具體的各
種規則應該怎麼寫,只能寫一個大的過濾:
JkMount /* controller
JkMount /*.do controller
將mod_jk.conf末尾改成上面這樣。重啓apache,你就可以看到RONE登陸界面了
完成以上步驟後,直接用瀏覽器訪問apache地址,就能進入Tomcat主頁。關閉其中一個Tomcat服務器,其它Tomcat也能訪問。

命令相關

  • 重啓apache2:
/etc/init.d/apache2 restart
  • 編輯workers:
vi /etc/libapache2-mod-jk/workers.properties
  • 編輯apache2.conf
vi /etc/apache2/apache2.conf
  • 編輯jk.conf
vi /etc/apache2/mods-enabled/jk.conf

完整配置貼出,方便以後查閱

  • jk.conf
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Configuration Example for mod_jk
# used in combination with Apache 2.2.x

<IfModule jk_module>

    # We need a workers file exactly once
    # and in the global server
    JkWorkersFile /etc/libapache2-mod-jk/workers.properties

    # Our JK error log
    # You can (and should) use rotatelogs here
    JkLogFile /var/log/apache2/mod_jk.log

    # Our JK log level (trace,debug,info,warn,error)
    JkLogLevel info

    # Our JK shared memory file
    JkShmFile /var/log/apache2/jk-runtime-status

    # Define a new log format you can use in any CustomLog in order
    # to add mod_jk specific information to your access log.
    # LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{Cookie}i\" \"%{Set-Cookie}o\" %{pid}P %{tid}P %{JK_LB_FIRST_NAME}n %{JK_LB_LAST_NAME}n ACC %{JK_LB_LAST_ACCESSED}n ERR %{JK_LB_LAST_ERRORS}n BSY %{JK_LB_LAST_BUSY}n %{JK_LB_LAST_STATE}n %D" extended_jk

    # This option will reject all requests, which contain an
    # encoded percent sign (%25) or backslash (%5C) in the URL
    # If you are sure, that your webapp doesn't use such
    # URLs, enable the option to prevent double encoding attacks.
    # Since: 1.2.24
    JkOptions +RejectUnsafeURI

    # This option will collapse multiple adjacent slashes
    # in request URLs before looking for mount or unmount
    # matches.
    # Since: 1.2.41
    # JkOptions +CollapseSlashesAll

    # After setting JkStripSession to "On", mod_jk will
    # strip all ";jsessionid=..." from request URLs it
    # does *not* forward to a backend.
    # This is useful, if all links in a webapp use
    # URLencoded session IDs and parts of the static
    # content should be delivered directly by Apache.
    # Of course you can also do it with mod_rewrite.
    # Since: 1.2.21
    # JkStripSession On

    # Start a separate thread for internal tasks like
    # idle connection probing, connection pool resizing
    # and load value decay.
    # Run these tasks every JkWatchdogInterval seconds.
    # Since: 1.2.27
    JkWatchdogInterval 60

    # Configure access to jk-status and jk-manager
    # If you want to make this available in a virtual host,
    # either move this block into the virtual host
    # or copy it logically there by including "JkMountCopy On"
    # in the virtual host.
    # Add an appropriate authentication method here!
    <Location /jk-status>
        # Inside Location we can omit the URL in JkMount
        JkMount jk-status
        Order deny,allow
        Deny from all
        Allow from 127.0.0.1
    </Location>
    <Location /jk-manager>
        # Inside Location we can omit the URL in JkMount
        JkMount jk-manager
        Order deny,allow
        Deny from all
        Allow from 127.0.0.1
    </Location>

    # If you want to put all mounts into an external file
    # that gets reloaded automatically after changes
    # (with a default latency of 1 minute),
    # you can define the name of the file here.
    # JkMountFile conf/extra/uriworkermap.properties

    # Example for Mounting a context to the worker "balancer"
    # The URL syntax "a|b" instantiates two mounts at once,
    # the first one is "a", the second one is "ab".
    JkMount /* loadbalancer

    # Example for UnMounting requests for all workers
    # using a simple URL pattern
    # Since: 1.2.26
    # JkUnMount /myapp/static/* *

    # Example for UnMounting requests for a named worker
    # JkUnMount /myapp/images/* balancer

    # Example for UnMounting requests using regexps
    # SetEnvIf REQUEST_URI "\.(htm|html|css|gif|jpg|js)$" no-jk

    # Example for setting a reply timeout depending on the request URL
    # Since: 1.2.27
    # SetEnvIf Request_URI "/transactions/" JK_REPLY_TIMEOUT=600000

    # Example for disabling reply timeouts for certain request URLs
    # Since: 1.2.27
    # SetEnvIf Request_URI "/reports/" JK_REPLY_TIMEOUT=0

    # IMPORTANT: Mounts and virtual hosts
    # If you are using VirtualHost elements, you
    # - can put mounts only used in some virtual host into its VirtualHost element 
    # - can copy all global mounts to it using "JkMountCopy On" inside the VirtualHost
    # - can copy all global mounts to all virtual hosts by putting
    #   "JkMountCopy All" into the global server
    # Since: 1.2.26

</IfModule>
  • workers.properties
# workers.properties -
#
# This file is a simplified version of the workers.properties supplied
# with the upstream sources. The jni inprocess worker (not build in the
# debian package) section and the ajp12 (deprecated) section are removed.
#
# As a general note, the characters $( and ) are used internally to define
# macros. Do not use them in your own configuration!!!
#
# Whenever you see a set of lines such as:
# x=value
# y=$(x)\something
#
# the final value for y will be value\something
#
# Normaly all you will need to do is un-comment and modify the first three
# properties, i.e. workers.tomcat_home, workers.java_home and ps.
# Most of the configuration is derived from these.
#
# When you are done updating workers.tomcat_home, workers.java_home and ps
# you should have 3 workers configured:
#
# - An ajp13 worker that connects to localhost:8009
# - A load balancer worker
#
#

# OPTIONS ( very important for jni mode )

#
# workers.tomcat_home should point to the location where you
# installed tomcat. This is where you have your conf, webapps and lib
# directories.
#
#workers.tomcat_home=/opt/tomcat8

#
# workers.java_home should point to your Java installation. Normally
# you should have a bin and lib directories beneath it.
#
#workers.java_home=/usr/lib/jvm/java1.8

#
# You should configure your environment slash... ps=\ on NT and / on UNIX
# and maybe something different elsewhere.
#
ps=/

#
#------ ADVANCED MODE ------------------------------------------------
#---------------------------------------------------------------------
#

#
#------ worker list ------------------------------------------
#---------------------------------------------------------------------
#
#
# The workers that your plugins should create and work with
#
worker.list=loadbalancer,tomcat1,tomcat2

#
#------ ajp13_worker WORKER DEFINITION ------------------------------
#---------------------------------------------------------------------
#

#
# Defining a worker named ajp13_worker and of type ajp13
# Note that the name and the type do not have to match.
#
#============tomcat1==============
worker.tomcat1.port=8009
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1

#=============tomcat2=============
worker.tomcat2.port=8009
worker.tomcat2.host=10.134.0.88
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1
#
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=tomcat1,tomcat2
worker.loadbalancer.sticky_session=false
  • apache2.conf
# This is the main Apache server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.4/ for detailed information about
# the directives and /usr/share/doc/apache2/README.Debian about Debian specific
# hints.
#
#
# Summary of how the Apache 2 configuration works in Debian:
# The Apache 2 web server configuration in Debian is quite different to
# upstream's suggested way to configure the web server. This is because Debian's
# default Apache2 installation attempts to make adding and removing modules,
# virtual hosts, and extra configuration directives as flexible as possible, in
# order to make automating the changes and administering the server as easy as
# possible.

# It is split into several files forming the configuration hierarchy outlined
# below, all located in the /etc/apache2/ directory:
#
#   /etc/apache2/
#   |-- apache2.conf
#   |   `--  ports.conf
#   |-- mods-enabled
#   |   |-- *.load
#   |   `-- *.conf
#   |-- conf-enabled
#   |   `-- *.conf
#   `-- sites-enabled
#       `-- *.conf
#
#
# * apache2.conf is the main configuration file (this file). It puts the pieces
#   together by including all remaining configuration files when starting up the
#   web server.
#
# * ports.conf is always included from the main configuration file. It is
#   supposed to determine listening ports for incoming connections which can be
#   customized anytime.
#
# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
#   directories contain particular configuration snippets which manage modules,
#   global configuration fragments, or virtual host configurations,
#   respectively.
#
#   They are activated by symlinking available configuration files from their
#   respective *-available/ counterparts. These should be managed by using our
#   helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
#   their respective man pages for detailed information.
#
# * The binary is called apache2. Due to the use of environment variables, in
#   the default configuration, apache2 needs to be started/stopped with
#   /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
#   work with the default configuration.


# Global configuration
#

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE!  If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the Mutex documentation (available
# at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
#ServerRoot "/etc/apache2"

#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
Mutex file:${APACHE_LOCK_DIR} default

#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5


# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log

#
# LogLevel: Control the severity of messages logged to the error_log.
# Available values: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the log level for particular modules, e.g.
# "LogLevel info ssl:warn"
#
LogLevel warn

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

# Include list of ports to listen on
Include ports.conf


# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

#<Directory /srv/>
#   Options Indexes FollowSymLinks
#   AllowOverride None
#   Require all granted
#</Directory>




# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#
AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>


#
# The following directives define some format nicknames for use with
# a CustomLog directive.
#
# These deviate from the Common Log Format definitions in that they use %O
# (the actual bytes sent including headers) instead of %b (the size of the
# requested file), because the latter makes it impossible to detect partial
# requests.
#
# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
# Use mod_remoteip instead.
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.

# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
  • 000-default.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.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    # 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
    JkMount /* loadbalancer
    # 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>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章