Skip to content

Instantly share code, notes, and snippets.

@ipanardian
Last active July 18, 2018 11:06
Show Gist options
  • Save ipanardian/a6ae33aa3139e4184dcd1abe380efb09 to your computer and use it in GitHub Desktop.
Save ipanardian/a6ae33aa3139e4184dcd1abe380efb09 to your computer and use it in GitHub Desktop.
Install and Configure Nginx on Mac

Install

$ brew install nginx

Setelah install jalankan nginx.
$ sudo nginx

Testing

Test apakah nginx sudah running, buka url http://localhost:8080.

Ganti default port

Nginx default port adalah 8080, kita akan menggantinya ke port 80.
$ sudo nginx -s stop

Kemudian buka nginx.conf
$ sudo nano /usr/local/etc/nginx/nginx.conf

Ganti

server {
	listen      8080;

Menjadi

server {
	listen      80;

Simpan konfigurasi.

Membuat Virtual Host

  1. Buat direktori bernama sites-available dan sites-enabled di /usr/local/etc/nginx/.
  2. Buat file foo.conf di dalam direktori sites-available.
  3. Paste source code berikut ke file foo.conf.
server {
   listen 80; 

   root /Users/ipan/workspace/foo;
   index index.php;

   server_name  beta.foo.dev;
   server_name  member.foo.dev;
   server_name  microsite.foo.dev;

   location / {
      try_files $uri $uri/ /index.php;
   }

   location ~ \.php$ {
      try_files $uri =404;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
   }
 }
  1. Kemudian buat symlink
    $ ln -s /usr/local/etc/nginx/sites-available/foo.conf /usr/local/etc/nginx/sites-enabled/foo.conf

  2. Lalu buka file /usr/local/etc/nginx/nginx.conf, masukan code berikut di dalam section http.
    include /usr/local/etc/nginx/sites-enabled/*.conf;

  3. Setelah itu buka file hosts
    $ sudo nano /etc/hosts

  4. Tambahkan host dibawah ini

127.0.0.1 beta.foo.dev
127.0.0.1 member.foo.dev
127.0.0.1 microsite.foo.dev
  1. Reload Nginx
    $ sudo nginx -s reload

  2. Test URL Test URL web, jika masih belum restart notebook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment