nginx - 在 mamp 免费版上使用 nginx 设置 vhost
问题描述
我想在 mamp 上设置虚拟主机,同时使用 nginx 而不是默认的 apache 服务器。
我浏览了堆栈溢出和网络,但我能找到的要么是纯 nginx(谈到sites-available
默认情况下未在 mamp 上创建的文件夹),要么是关于 mamp 上带有 apache 的虚拟主机,或者是关于 mamp PRO 上带有 nginx 的虚拟主机。
我确实设法切换到 nginx,但我现在只能看到 403 错误(当我回到 apache 服务器时,我所有的虚拟主机都在工作)。我确实在我的主机文件中添加了这些行,但我无法让虚拟主机工作。这是我的MAMP/conf/nginx/nginx.conf
http {
...
server {
...
location / {
index index.html index.php;
}
location my-vhost-name.com {
root /Users/myName/Document/projectParentFolder/projectFolder;
index index.html index.php;
}
}
}
当我访问 my-vhost-name.com 时,我收到了来自 nginx 的 403 错误消息。
谢谢您的帮助。
解决方案
在 MAMP/conf/nginx 目录中,我
sites-enabled
为各个站点创建了一个配置文件夹。我为该站点添加了一个配置
example.com
文件MAMP/conf/nginx/sites-enabled
我将配置变量添加到
MAMP/conf/nginx/sites-enabled/example.com
:server { charset utf-8; client_max_body_size 128M; sendfile off; listen 80; server_name example.com; root /Applications/MAMP/htdocs/example.com/; index index.php; location / { # Redirect everything that isn't a real file to index.php try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/Applications/MAMP/Library/logs/fastcgi/nginxFastCGI.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
在配置主文件的末尾
(MAMP/conf/nginx/nginx.conf)
,我连接了sites-enabled
文件夹中的所有配置:include sites-enabled/*; }
重启 MAMP
推荐阅读
- c# - 多视图和 MaintainScrollPositionOnPostback
- javascript - 通过外部交互更新 React 组件状态
- html - 删除表格之间的间距
- azure - 如何设置我的 Azure 帐户以通过 REST API 进行 ARM 部署?
- laravel - 在 laravel 5.5 中不显示 Flash 消息
- python - 如何使用 for 循环改进子图部分?
- android - 将 Firebase 应用推送到应用商店后如何对其进行迭代?
- javascript - 如何在 React-Native 中从 firebase 返回一组孩子
- mysql - MySQL + EF 更新很慢?
- objective-c - 我们什么时候需要将框架添加到 Xcode 项目中?