mac开启原生服务器
- 命令行 开启appache
//开启 apache: sudo apachectl start
//重启 apache: sudo apachectl restart
//关闭 apache: sudo apachectl stop
注意⚠️:回车会提示输入电脑的密码,然后访问http://127.0.0.1/测试一下,成功则显示it works!
- 访问的文件路径是
点击Finder,然后Command+Shift+G,前往如下路径 (mac下Apache服务器的文件路径 /Library/WebServer/Documents )
将文件放在该目录即可访问
不使用的时候记得关闭,消耗内存
- 注意访问目录下文件的时候有可能提示没有权限(状态码403)
访问地址http://127.0.0.1/webroot/login.html
错误提示❌:Forbidden
You don't have permission to access /webroot/login.html on this server.
Server unable to read htaccess file, denying access to be safe
解决方案:
- 更改httpd.conf配置文件
- 给文件添加777权限执行命令
chmod 777 webroot
✅
- 变更默认文件路径/Library/WebServer/Documents为自定义路径/Users/xueersi/workspace/Sites/
更改步骤:
- A 打开文件 /private/etc/apache2/httpd.conf
# LoadModule userdir_module libexec/apache2/mod_userdir.so
对该行解注释 (去掉#)
- B 在用户名下创建文件夹Sites(要变更到的目录)路径/Users/xueersi/workspace/Sites/
- C 修改/private/etc/apache2/httpd.conf文件中的DocumentRoot
DocumentRoot "/Users/xueersi/workspace/Sites/"
<Directory "/Users/xueersi/workspace/Sites/">
- D 创建 用户名.conf 配置文件 /private/etc/apache2/users/xueersi.conf
输入代码
<Directory "/Users/tangjr/Sites/">
Options Indexes MultiViews
AllowOverride All
Require all granted # OSX 10.10 / Apache 2.4
</Directory>
- E 找到/private/etc/apache2/httpd.conf文件中
Options FollowSymLinks Multiviews
修改为
Options FollowSymLinks Multiviews Indexes
- F 重新启动appache服务器
sudo apachectl restart
注意⚠️: 如果restart后不生效,则执行stop后start
参考链接mac原生服务器文件地址变更
网友评论