It's straightforwards to install Nginx on OSX with bre - parisnakitakejser.com ![]()
Nginx (pronounced "engine x") is a web server. It can act as a reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer and an HTTP cache - wikipedia ![]()
# Installation on OSX
Installation on OSX is painless:
brew install nginx
However if you want to install modules like lua you can use the handy:
The only issue is with that the default install of nginx with homebrew does not include LUA support.
# Tidy your folders
You may want to set up these folders:
/usr/local/etc/nginx/sites-enabled/ /usr/local/etc/nginx/sites-enabled/
And make some symbolic links:
cd /usr/local/etc/nginx/sites-enabled ln -s ../sites-available/default.conf ln -s ../sites-available/default-ssl.conf
Use this command to get NGINX to start up when you boot up your OS X.
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
The file locations on OSX for nginx as installed by default using homebrew are:
/usr/local/etc/nginx/nginx.conf /usr/local/etc/nginx/sites-available/default.conf /usr/local/etc/nginx/sites-available/default-ssl.conf /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
# Controlling Nginx
If you need full control over your NGINX webserver you can use this commands to start, stop and restart NGINX.
sudo nginx # start sudo nginx -s stop # stop sudo nginx -s reload # restart
Now its time to look about NGINX working, go to your browser and type
http://localhost:8080
To check which nginx processes are running try:
pgrep nginx
To see more clearly what these processes are:
ps waux | grep nginx ... root 91487 0.0 0.0 2463900 436 ... nginx: master process nginx ...
to tell you if nginx is still running, and
lsof -i 4tcp | grep 8080
will tell you which process is holding the 8080 port if it's not nginx.
And you can kill the master process manually with (replace 91728 and enter the pid from the results above):
kill -QUIT 91728
# Setting up NGINX First we need to change in our NGINX config file, open NGINX config file in your editor, i primary use nano:
nano /usr/local/etc/nginx/nginx.conf
My nginx.conf file look like this:
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; events { worker_connections 1024; } http { include mime.types; include sites-enabled/*; # load virtuals config sendfile on; keepalive_timeout 65; # gzip on; # gzip_disable "MSIE [1-6]\.(?!.*SV1)"; server { listen 8080; server_name localhost; location / { root /Users/{username}/{webfolder}; try_files $uri $uri/ /index.php?$args ; index index.php; } # configure *.PHP requests location ~ \.php$ { root /Users/{username}/{webfolder}; try_files $uri $uri/ /index.php?$args ; index index.html index.htm index.php; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_intercept_errors on; include fastcgi_params; } } }
Now you need to change {username} to your Mac OS X user, changes {webfolder} to this folder you want to have your site in.
# Setup Virtual Hosts First of all, you need to create 2 new folders to handle our next step:
mkdir /usr/local/etc/nginx/sites-available mkdir /usr/local/etc/nginx/sites-enabled
sites-available are all your virtual config files and sites-enabled hold a symbolic link from sites-available folder so you can remove and create new config if you want new sites added.
Next step is create your first virtualhost file:
nano /usr/local/etc/nginx/sites-available/{hostfile}
Change {hostfile} to your domain eg. test.local
My virtualhost file look likes this:
server { listen *:8080; server_name {test-domain}; #access_log /Users/{username}/{webfolder}/{hostfile}/log/access.log; #error_log /Users/{username}/{webfolder}/{hostfile}/log/error.log; root /Users/{username}/{webfolder}/{hostfile}; index index.html index.htm index.php; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { try_files $uri $uri/ /index.php?$args; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_intercept_errors on; include fastcgi_params; } }
change {username}, {webfolder} and {hostfile} width there names your ealier have changes the names on.
When you have save this folder you go to the sites-enabled and run the following command.
ln -s /usr/local/etc/nginx/sites-available/{hostfile} /usr/local/etc/nginx/sites-enabled/{hostfile}
Restart you NGINX webserver now:
sudo nginx -s reload
Look in your browser about its working well:
http://{hostfile}:8080
Remember to changes your computers hostfile if not you have done that already in sudo nano /etc/hosts put this line in your hostfile
127.0.0.1 {test-domain}
# fcgiwrap
You're going to need to install fcgiwrap to get nginx working with revIgniter - nginx.com ![]()
brew install fcgiwrap
# See also
For a quick and dirty php setup see - masnun.com ![]()