Apache的一点小坑

其实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或者其他目录,则会失败;需要自己新建目录方可。
该问题要继续追踪,以后可能会继续更新。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 一、概述 二、编译安装 三、httpd服务基础 四、httpd.conf配置文件 五、httpd服务访问控制 六、...
    紫_轩阅读 1,092评论 0 0
  • 1、第八章 Samba服务器2、第八章 NFS服务器3、第十章 Linux下DNS服务器配站点,域名解析概念命令:...
    哈熝少主阅读 3,925评论 0 10
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,766评论 19 139
  • httpd相关: httpd程序版本: 。1.3 停止维护 。2.0 。 2.2 event为测试使用 。 2.4...
    ckhzw阅读 515评论 0 0
  • 每天坚持做自己有多难?每天坚持做自己喜欢的事情又有多难?每天坚持做自己真正向往的样子更是何其的不容易?你能...
    紫燕冰凝阅读 582评论 0 0

友情链接更多精彩内容