apache2官方文檔 http://httpd.apache.org/docs/...php
# 這是apache主要的服務器配置文件,它包含一些服務器的配置指令,詳情參考 http://httpd.apache.org/docs/2.4/ 及查看Debian特殊提示 /usr/share/doc/apache2/README.Debian # # # 在Debian中Apache2配置工做概述,它與web服務器的配置有一些區別 # 被分割成了多個文件,但全部的配置文件仍是在 /etc/apache2/ 文件夾中 # # /etc/apache2/ # |-- apache2.conf # | `-- ports.conf # |-- mods-enabled # | |-- *.load # | `-- *.conf # |-- conf-enabled # | `-- *.conf # `-- sites-enabled # `-- *.conf # # # * apache2.conf 是主配置文件. # # * ports.conf 最終是包含到上面的主配置文件中. # # * 在mods-enabled/, conf-enabled/ 和 sites-enabled/這幾個目錄下的配置文件,分別用來管理模塊、全局配置片斷,虛擬主機配置 # 它們都是 *-available文件夾下的一個符號連接,也就是同windows下的快捷方式是同一種類型,對因而否啓用的管理,能夠使用如下命令 # 如開啓rewrite模塊,使用 root@ubuntu:~# a2enmod rewrite,會生成連接/etc/apache2/mods-enabled/rewrite.load,關閉是 a2dismod rewrite # 一樣對虛擬主機命令有 a2ensite和a2dissite,對全局配置有 a2enconf∑ a2disconf # # * 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. # 全局配置 # # # ServerRoot: 目錄樹的頂部,它下面放服務器的配置文件、錯誤和日誌文件 # # 提示! 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. # # 不要在目錄的結尾加斜槓 # #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 # # 日誌級別: 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 # 導入模塊配置文件: IncludeOptional mods-enabled/*.load IncludeOptional mods-enabled/*.conf # 導入須要偵聽端口的列表 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: 會在每一個文件夾中查該文件,它包含一些附加配置指令,也可參閱指令 AllowOverride # AccessFileName .htaccess # # FilesMatch是一個正則表達式,表示以.ht開頭的文件,下面的意思是,象.htaccess 和 .htpasswd這一類以.ht開頭的文件,不能被web客戶端瀏覽 <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 # 導入虛擬主機的配置: IncludeOptional sites-enabled/*.conf # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
虛擬主機設置
參考指令<VirtualHost> http://httpd.apache.org/docs/...
建配置文件/etc/apache2/sites-available/www.chuse.store.conf
,內容以下html
<VirtualHost *:80> ServerAdmin wang@chuse.store DocumentRoot /var/www/chuse/store ServerName www.chuse.store ErrorLog /var/log/apache2/www.chuse.store-error_log TransferLog /var/log/apache2/www.chuse.store-access_log </VirtualHost>
啓動網站web
root@ubuntu:~# a2ensite www.chuse.store.conf root@ubuntu:~# service apache2 restart
建一個測試文件 /var/www/chuse/store/index.php正則表達式
修改宿主機中C:\Windows\System32\drivers\etc\hosts
,加一行127.0.0.1 www.chuse.store
apache
參考 https://www.jianshu.com/p/223...
參考 https://www.cnblogs.com/xing9...ubuntu