Sunday, April 19, 2015

Using Nginx on Mac OSX

To install Nginx on your Mac you can use simply brew command:
$ brew install nginx 
Default Nginx server name is localhost with 8080 port. So you can see default Nginx page by entering http://localhost:8080 address. Let's change something:

Changing default server name and port
Nginx.conf located at /usr/local/etc/nginx/nginx.conf dir. Open it with your favorite editor, to me the Vim:
$ vim /usr/local/etc/nginx/nginx.conf
 You'll see default server configuration like this:
server {    listen 8080;    server_name locahost;
    ## other things}
Change them with what you want and save the file. To reload Nginx configuration you should restart Nginx by calling these:
$ sudo nginx -s stop$ sudo nginx 
Including multi server defination from different files
Aww, cool topic. To keep different server definations in different files, you should need to this. Open nginx.conf, locate your cursor to the end of http defination block and simple paste this two lines:
$ include /usr/local/etc/nginx/conf.d/*.conf;
$ include /usr/local/etc/nginx/sites-enabled/*.conf;
Now your can create symlinks to these directories. Of course, don't forget to restart Nginx!

No comments:

Post a Comment