Mac OS X 开启Http Ftp服务

今天想把我们游戏的app包和更新patch放到服务器上,方便大家下载/更新。手头没有linux服务器,工作用的我有一台Windows PC,一台mac mini。windows机器是工作主机器,不能作为文件服务器,而且mac省电/静音,就折腾了一下Mac开启Http和Ftp服务。Mac系统自带了Apache和Ftp服务,只需要开启、配置一下就可以了。

开启Apache

#sudo apachectl start

终端输入上述命令,apache就开启了。在本机浏览器中输入http://localhost,可以看到页面显示内容”It works!”。该页面位于apache的默认根目录/Library/WebServer/Documents/。

配置Apache

  1. 打开Apche的配置文件,/etc/apache2/httpd.conf
  2. 在httpd.conf中找到#Include /private/etc/apache2/extra/httpd-vhosts.conf,去掉前面的#,保存。
  3. 打开Apache虚拟主机配置文件,/etc/apache2/extra/httpd-vhosts.conf。
  4. 注释掉文件中配置的2个虚拟主机例子
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/usr/docs/dummy-host.example.com"
    ServerName 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
</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
</VirtualHost>

添加自己的配置

<VirtualHost *:80>
    DocumentRoot "/Users/YourUserName/Desktop/update"
    ServerName localhost
    ErrorLog "/private/var/log/apache2/error_log"
    CustomLog "/private/var/log/apache2/access_log" common
    <Directory />
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

在alias模块里加
Alias update /Users/YourUserName/Desktop/update
保存后重启Apache,#sudo apachectl restart
5. 在浏览器里访问http://localhost/update,error_log提示”Permission Denied”
官方文档http://wiki.apache.org/httpd/13PermissionDenied,里讲到Apache对访问到的各层级目录都要求644权限,我之前只设置了update目录的,要逐层向上把路径中所有层级目录都chmod 644 dir
6. error_log又提示”Client denied by server configuration”
官方文档https://wiki.apache.org/httpd/ClientDeniedByServerConfiguration,真是好啊,讲的明明白白。针对Apache 2.2访问权限配置是

<Directory /var/www/example.com>
  Order deny,allow
  Deny from all
</Directory>

针对2.4配置是

<Directory /var/www/example.com>
  Require all denied
</Directory>
#sudo apachectl -v

查看我的Mac自带的Apache版本是2.4.16,修改一下配置

<VirtualHost *:80>
    DocumentRoot "/Users/macmini3/Desktop/update"
    ServerName localhost
    ErrorLog "/private/var/log/apache2/sites-error_log"
    CustomLog "/private/var/log/apache2/sites-access_log" common
    <Directory />
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Require all granted
#        Order deny,allow
#        Allow from all
    </Directory>
</VirtualHost>

7.再访问http://localhost/update,如愿正常显示页面了。

Ftp服务

开启和关闭的命令分别是以下两条,很简单

sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist
sudo -s launchctl unload -w /System/Library/LaunchDaemons/ftp.plist

想开机自启动ftp服务就编辑ftp.plist

 <dict>
        <key>Disabled</key>  --> 改为Enabled
        <true/>

访问的用户名和密码是登录mac系统的用户名和密码。

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值