Deploying on VPS with Nginx
Complete guide to setting up Nginx web server on a Virtual Private Server
Instructions for deploying stuff: Okay, here are the Nginx setup instructions from the [[Nginx Setup]] note:
- Install Nginx:
sudo apt update sudo apt install nginx
- Adjust Firewall:
- List application configurations:
sudo ufw app list
(Output should include ‘Nginx HTTP’, ‘Nginx HTTPS’, ‘Nginx Full’) - Allow HTTP traffic:
sudo ufw allow 'Nginx HTTP'
- Verify status:
sudo ufw status
- List application configurations:
- Check Web Server:
- Check systemd status:
systemctl status nginx
- Get server IP:
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
(or usecurl -4 icanhazip.com
) - Access
http://your_server_ip
in a browser. You should see the default Nginx landing page.
- Check systemd status:
- Set Up Server Blocks (Optional but Recommended):
- Create a directory for your domain:
sudo mkdir -p /var/www/your_domain/html
- Set ownership:
sudo chown -R $USER:$USER /var/www/your_domain/html
- Set permissions:
sudo chmod -R 755 /var/www/your_domain
- Create a sample
index.html
:nano /var/www/your_domain/html/index.html
(Add some basic HTML) - Create a new server block config file:
sudo nano /etc/nginx/sites-available/your_domain
- Paste the basic server block configuration (see [[Nginx Setup]] for the template).
- Enable the file by creating a symbolic link:
sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/
- Unlink the default config to avoid conflicts (if needed):
sudo unlink /etc/nginx/sites-enabled/default
- Test Nginx configuration:
sudo nginx -t
- Restart Nginx:
sudo systemctl restart nginx
- Create a directory for your domain:
- Important Nginx Files and Directories:
/etc/nginx
: Main configuration directory./etc/nginx/nginx.conf
: Main configuration file./etc/nginx/sites-available/
: Directory for per-site server blocks./etc/nginx/sites-enabled/
: Directory containing links to enabled server blocks./var/log/nginx/access.log
: Logs every request./var/log/nginx/error.log
: Logs Nginx errors.