Nginx is one of the fastest server for web. So installing it in your mac is not so difficult. I am describing here about how to Install Nginx mac brew
First you may need to stop the apache, that already running in your system. For stop apache
sudo apachectl stop sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
Run the below command to install nginx
brew install nginx
Then you can see the nginx in the browser with http://localhost:8080
For stopping nginx run
sudo nginx -s stop
For start nginx run
sudo nginx
To make a proxy in nginx. Go to the servers directory
cd /usr/local/nginx/servers
then create a server name example-proxy.conf with below configuration.
server { listen 80; location / { proxy_pass http://192.x.x.2; } }
Nginx server block examples
Server block example for php website
server { listen 80; server_name dev-nginx.local; root /Users/ajitdas/php-site; location / { index index.html index.htm index.php ; } charset utf-8; # Pass PHP Scripts To FastCGI Server location ~ \.php$ { fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_pass 127.0.0.1:9074; fastcgi_split_path_info ^(.+\.php)(/.+)$; } }
Server block example for Wordpress with ssl
server { listen 80 default_server; listen 443 ssl http2; ssl_certificate /usr/local/etc/nginx/ssl/localhost.crt; ssl_certificate_key /usr/local/etc/nginx/ssl/localhost.key; server_name test-wordpress.local; root /Users/ajitdas/wp-site; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?q=$uri&$args; } charset utf-8; # Pass PHP Scripts To FastCGI Server location ~ \.php$ { fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_pass 127.0.0.1:9074; fastcgi_split_path_info ^(.+\.php)(/.+)$; } }
Server block example for Laravel
server { listen 80; server_name laravel-site.local; root /Users/ajitdas/laravel-site/public; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php$is_args$args; } charset utf-8; # Pass PHP Scripts To FastCGI Server location ~ \.php$ { fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_pass 127.0.0.1:9074; fastcgi_split_path_info ^(.+\.php)(/.+)$; } }
If you have any question about how to install Nginx mac brew. Please make comment. We will help you.