Skip to content

Instantly share code, notes, and snippets.

@lnxph-devops-sareno
Last active September 30, 2020 07:42
Show Gist options
  • Save lnxph-devops-sareno/cd6a2e86853385a2eb141601645009da to your computer and use it in GitHub Desktop.
Save lnxph-devops-sareno/cd6a2e86853385a2eb141601645009da to your computer and use it in GitHub Desktop.
Setup a Nginx local environment for testing

Nginx - Setup a local environment for testing

Create a Nginx configuration

/etc/nginx/sites-enabled/example.com.conf

server {
    listen 80;
    server_name example.com www.example.com;
    
    location / {
        add_header Content-Type text/plain;
        return 200 'Hello World!';
    }
}

Restart Nginx to load configurations

$ nginx -t && systemctl restart nginx  # service nginx restart

Add domain name to hosts file

Edit hosts file

$ nano /etc/hosts

Append to the end of the file

127.0.0.1 localhost
# ....
127.0.0.1 example.com www.example.com
Definition
  • example.com www.example.com the domains that will be map to IP Address.
  • 127.0.0.1 or localhost, the domain names that matches the query will be mapped to this address, this case are example.com and www.example.com domains. External IP Adresses are also valid, of course 😂.

Checking

$ curl http://example.com
$ curl http://www.example.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment