magento第二课:使用Apache web服务器搭建网站

apache2官方文档 http://httpd.apache.org/docs/...

配置文件

# 这是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,内容如下

<VirtualHost *:80>
    ServerAdmin [email protected]
    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>

启动网站

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

目录映射

参考 https://www.jianshu.com/p/223...
参考 https://www.cnblogs.com/xing9...

相关推荐