Deploying on VPS with Nginx
Outdated guide to setting up a VPS
Instructions for deploying stuff generally, but I just made a goated script to install most of these things on any debian based OS. I usually just install debian, and then run my script. I don’t even remember where it is though. I think its on my laptop, which I returned back to work. So yeah.. should be on my GCP cloud should have it hopefully.
- 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_ipin 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.