【问题标题】:setup vhost with nginx on mamp free version在 mamp 免费版上使用 nginx 设置 vhost
【发布时间】:2019-04-20 21:37:06
【问题描述】:

我想在 mamp 上设置虚拟主机,同时使用 nginx 而不是默认的 apache 服务器。

我浏览了堆栈溢出和网络,但我能找到的要么是纯 nginx(谈到 sites-available 文件夹,它不是默认在 mamp 上创建的),要么是关于 mamp 上带有 apache 的 vhost,或者是关于带有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 错误消息。

感谢您的帮助。

【问题讨论】:

  • 您找到解决方案了吗?我有同样的问题
  • @DzulfikarAdiPutra 我没有找到也没有搜索太久,因为我最终只是使用我更了解的 apache 虚拟主机。我问过的人建议我更改/Applications/MAMP中的设置,但也告诉我如果我开始接触mamp设置,我不妨从MAMP独立安装nginx,这样会更灵活。希望这对您有所帮助。
  • 我明白了,谢谢你的回答。我最终卸载了 MAMP,然后安装了 Laragon。
  • 好的。如果有人遇到此问题,感谢您提供信息。也许您可以将此作为答案,以防遇到同样问题的人来到这里,也许 laragon 将是他们需要的解决方案。 (虽然我不会赞成或反对这个答案,因为我不知道它是否对我遇到的问题有用,但其他人可能会这样做。)

标签: nginx mamp vhosts


【解决方案1】:
  1. 在 MAMP/conf/nginx 目录中,我为各个站点的配置创建了一个 sites-enabled 文件夹。

  2. 我在MAMP/conf/nginx/sites-enabled 中添加了站点example.com 的配置文件

  3. 我将配置变量添加到 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;
         }
     }
    
  4. 在配置主文件(MAMP/conf/nginx/nginx.conf) 的末尾,我连接了sites-enabled 文件夹中的所有配置:

        include sites-enabled/*;
     }
    
  5. 重启 MAMP

【讨论】:

    猜你喜欢
    • 2014-12-06
    • 2019-06-29
    • 1970-01-01
    • 2017-11-23
    • 2017-12-01
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 2015-07-12
    相关资源
    最近更新 更多