使用Mamp Free版本安装带有Nginx的虚拟主机

问题描述 投票:1回答:1

我想在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错误消息。

谢谢您的帮助。

nginx mamp vhosts
1个回答
0
投票
  1. 在MAMP / conf / nginx目录中,我为各个站点的配置添加了“启用站点”文件夹。
  2. 在启用MAMP / conf / nginx / sites-enabled的站点中为“ example.com”添加配置文件
  3. 在配置主文件(MAMP / conf / nginx / nging.conf)的末尾,我连接了来自启用站点的文件夹中的所有配置:

       include sites-enabled/*;
    }
    
  4. 我已添加到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;
         }
     }
    
  5. 重新启动MAMP

一个选项是如何启动nginx。也可以用其他方式。

© www.soinside.com 2019 - 2024. All rights reserved.