3

I'd like to setup vhosts on mamp, while usin nginx instead of the default apache server.

I browsed stack overflow and the web, but all I could find was either about pure nginx (speaking about the sites-available folder which isn't created by default on mamp) or about vhost with apache on mamp or about vhosts with nginx on mamp PRO.

I did manage to switch to nginx, but all I can see now are 403 errors (and when I go back to apache server, all my vhosts are working). I did add the lines in my hosts file, but I can't manage to get the vhosts working. here is my 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;
        }
    }
}

And when I go to my-vhost-name.com, I have the 403 error message from nginx.

Thank you for your help.

Jonathan Simonney
  • 585
  • 1
  • 11
  • 25
  • did you find the solution? I have the same problem – Dzulfikar Adi Putra May 11 '19 at 11:40
  • @DzulfikarAdiPutra I didn't find nor searched for too long since I ended up simply working with the apache vhosts that I knew better. People whom I asked advised me to change the settings in `/Applications/MAMP` , but also told if I was beginning to touch mamp settings, I might as well install nginx independantly from MAMP, which would be more flexible. Hope this helps you. – Jonathan Simonney May 12 '19 at 06:35
  • I see, thank you for the answer. I ended up with uninstall MAMP, and install Laragon instead. – Dzulfikar Adi Putra May 12 '19 at 23:45
  • ok. Thank you for the information if someone comes upon this. Maybe you could put this as an answer, in case someone with same problem comes here, maybe laragon will be the solution they'll need. (I won't upvote nor downvote this answer though, as I have no clue whether it is useful to the problem I had, but other may do so.) – Jonathan Simonney May 13 '19 at 07:38

1 Answers1

4
  1. In the MAMP/conf/nginx directory, I created a sites-enabled folder for configs for individual sites.

  2. I added a config file for the site example.com in MAMP/conf/nginx/sites-enabled

  3. I added config vars to 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. At the end of the config main file (MAMP/conf/nginx/nginx.conf), I connect all the configs from the sites-enabled folder:

        include sites-enabled/*;
     }
    
  5. Restart MAMP

Mike
  • 41
  • 2