Basic Nginx Configuration

Fix permissions

Add user to www-data group

sudo usermod -a -G www-data {}

Check that www-data has the correct permissions

Directory 775
Files     664

Review www-data access to files

sudo -u www-data namei /path/to/file.html

Nginx Configuration

File location /etc/nginx/sites-enabled/default

server {
  listen 80;
  listen [::]:80;
  server_name {domain one};
  location / {
    proxy_set_header   X-Forwarded-For $remote_addr;
    proxy_set_header   Host $http_host;
    proxy_pass         "http://127.0.0.1:8080";
  }
}
server {
  listen 80;
  listen [::]:80;
  server_name {domain two};
  location / {
    root /path/to/files/;
    try_files $uri /index.html;
  }
}

Example with SSL:

server {
  listen 443 ssl;
  server_name {domain};
  ssl_certificate /etc/letsencrypt/live/{domain}/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/{domain}/privkey.pem;
  location / {
    proxy_set_header   X-Forwarded-For $remote_addr;
    proxy_set_header   Host $http_host;
    proxy_pass         "http://127.0.0.1:8080";
  }
}

Tags linux

Back