美文网首页
Apache的一点小坑

Apache的一点小坑

作者: 水田夏木 | 来源:发表于2017-07-26 23:08 被阅读68次

其实Apache+php的资料已经太多了,我也是因为试图搭建一个独立于公司的服务器用于智能家居平台的入口,所以不得不钻研一下服务器这一块。这篇文章简单记录一下踩过的小坑。

常见指令

sudo apachectl restart
sudo apachectl stop
sudo apachectl start

最后访问的是http://www.xxxx.com

外围目录

Apache默认目录在/etc/apache2下面。
虚拟主机配置在下一级的extra/目录下。
针对apache本身配置在http.conf文件中:
<Directory />
    AllowOverride none
    Require all granted
    Allow from all
</Directory>
DocumentRoot "/Library/WebServer/Documents"
 
 
<Directory "/Library/WebServer/Documents">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options FollowSymLinks Multiviews
    MultiviewsMatch Any
 
    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride None
 
    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>
这里可以做出修改。同时可以配置虚拟主机地址等内容。

虚拟主机

首先要在http.conf中放开虚拟主机的地址。
进入extra/文件夹,对httpd-vhosts.conf进行配置。
可以先把原来的文本注释掉,不然可能抱无法找到该地址的错误。

<VirtualHost *:80>
    #ServerAdmin webmaster@dummy-host.example.com
    #DocumentRoot "/usr/docs/dummy-host.example.com"
    #ServerName dummy-host.example.com
    #ServerAlias www.dummy-host.example.com
    #ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
    #CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
     DocumentRoot "/Library/WebServer/Documents"
    ServerName localhost
    ErrorLog "/private/var/log/apache2/localhost-error_log"
    CustomLog "/private/var/log/apache2/localhost-access_log" common
</VirtualHost>
 
<VirtualHost *:80>
    #ServerAdmin webmaster@dummy-host2.example.com
    #DocumentRoot "/usr/docs/dummy-host2.example.com"
    #ServerName dummy-host2.example.com
    #ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
    #CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
     DocumentRoot "/Users/itadmin/Sites/"
    ServerName www.zeke.com
    ErrorLog "/private/var/log/apache2/sites-error_log"
    CustomLog "/private/var/log/apache2/sites-access_log" common
    <Directory />
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order deny,allow
                Require all granted
      </Directory>
</VirtualHost>

访问地址配置

在虚拟主机中配置好相应的地址之后,你需要前往下面的地址进行配置:
sudo vi /etc/hosts
配置内容如下

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
#127.0.0.1      localhost
127.0.0.1       zekesite
127.0.0.1       ZekeSites
127.0.0.1       www.zeke.com
255.255.255.255 broadcasthost
::1             localhost

注意localhost这里仅仅保留了一个。

错误日志目录

在外围目录httpd.conf中进行配置,一般不必做出修改。
ErrorLog "/private/var/log/apache2/error_log"

端口监听

如果要修改端口,注意对同一个端口避免重复监听。
在httpd.conf中的端口,80端口默认似乎是关闭的。
可以同时监听多个端口。

设置文件访问权限,可能在extra/httpd-userdir.conf中,但是一般没有必要。

Include /private/etc/apache2/users/*.conf
<IfModule bonjour_module>
 #      RegisterUserSite customized-users
</IfModule>
 
#new code
<Directory "/Users/itadmin/Desktop/data/images">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Require all granted
</Directory>

疑问

如果尝试在浏览器中访问Documents或者其他目录,则会失败;需要自己新建目录方可。
该问题要继续追踪,以后可能会继续更新。

相关文章

网友评论

      本文标题:Apache的一点小坑

      本文链接:https://www.haomeiwen.com/subject/mzlakxtx.html