我想在Mamp上设置虚拟主机,而使用nginx而不是默认的Apache服务器。
我浏览了堆栈溢出和网络,但我所能找到的要么是关于纯nginx(谈论在Mamp上默认未创建的sites-available
文件夹),要么是关于在mamp上使用apache的vhost或关于与nginx的vhosts在MAMP PRO上。
我确实设法切换到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 / nging.conf)的末尾,我连接了来自启用站点的文件夹中的所有配置:
include 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
一个选项是如何启动nginx。也可以用其他方式。