Nginx ~ Setup - rohit120582sharma/Documentation GitHub Wiki

Mac machine

Install & Start

# Install Nginx. It will install on the location /usr/local/cellar
$ brew install nginx

# Start & stop the Nginx server/services
$ sudo nginx
$ sudo nginx -s stop

# Alternative command to start & stop the Nginx server/services
$ launchctl load /usr/local/cellar/nginx/1.17.8/homebrew.mxcl.nginx.plist
$ launchctl unload /usr/local/cellar/nginx/1.17.8/homebrew.mxcl.nginx.plist

# Check the installation
$ curl http://127.0.0.1:8080

Nginx configuration

# Check the root file path
$ cd /usr/local/var/www/html

# Change the server setting
$ vi /usr/local/etc/nginx/nginx.conf

# Test the configuration file
$ sudo nginx -t

# Restart
$ sudo nginx -s reload


Ubunto machine (Remote machine - Server)

Install & Start

# Install nginx
$ sudo apt update
$ sudo apt install nginx

# Confirm the installation
$ sudo nginx -t

# Start nginx
$ sudo service nginx start

Nginx configuration

  • Show and edit nginx configuration

    $ sudo less /etc/nginx/sites-available/default
    $ sudo vi /etc/nginx/sites-available/default
  • Edit nginx config

    # Base directory for requests
    root /var/www/html
    
    # Routing as reverse proxy
    # Modify the headers
    location / {
        proxy_pass http://127.0.0.1:3000/;
    }
  • Test the configuration file

    $ sudo nginx -t
  • Restart

    $ sudo service nginx reload

⚠️ **GitHub.com Fallback** ⚠️