在Mamp Free版本上使用Nginx设置虚拟主机

时间:2018-11-18 08:42:58

标签: nginx mamp vhosts

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

我浏览了堆栈溢出和网络,但是我所能找到的要么是关于纯nginx(谈论@Override public void setStructureBonusTileSpinner(int position, int currentTabNumber) { for(int i = 0; i < mSectionsPagerAdapter.getCount(); i++){ if(i != currentTabNumber) { String tag = "android:switcher:" + R.id.container + ":" + i; STab f = (STab) getSupportFragmentManager().findFragmentByTag(tag); if(f != null){ f.setStructureBonusTileSpinner(position); } } } } 文件夹,它在mamp上不是默认创建的),要么是关于在vamp上带有apache的vhost或关于在Mamp PRO上使用Nginx进行虚拟主机。

我确实设法切换到nginx,但是现在我只能看到403错误(当我回到apache服务器时,我所有的虚拟主机都在工作)。我的确在我的主机文件中添加了这些行,但是我无法使虚拟主机正常工作。这是我的sites-available

MAMP/conf/nginx/nginx.conf

当我访问my-vhost-name.com时,收到来自nginx的403错误消息。

谢谢您的帮助。

1 个答案:

答案 0 :(得分: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。可以通过其他方式实现。

相关问题