您的位置:首页 > 理论基础 > 计算机网络

Mac OS X 开启Http Ftp服务

2016-03-16 12:15 591 查看
今天想把我们游戏的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

打开Apche的配置文件,/etc/apache2/httpd.conf

在httpd.conf中找到#Include /private/etc/apache2/extra/httpd-vhosts.conf,去掉前面的#,保存。

打开Apache虚拟主机配置文件,/etc/apache2/extra/httpd-vhosts.conf。

注释掉文件中配置的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系统的用户名和密码。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mac http ftp apache