How to Set Up a VPS for Web Hosting
A VPS gives you a rented virtual server where you can install a web server, publish a site, and manage its files and settings. This guide covers a basic Ubuntu Server setup using Nginx, a domain name, and HTTPS; you will need a VPS account and access to its administrator console.
What You’ll Need
- A VPS running a supported Ubuntu Server release, with a public IPv4 address or IPv6 address reachable by your visitors. Choose enough memory and storage for your site; a small static site needs far less than a busy application.
- A domain name, if you want visitors to use a memorable address instead of the server IP. You can test the server by IP first.
- The VPS public IP address and initial login details, preferably an SSH key. Keep the provider’s recovery console available in case you block remote access.
- A computer with an SSH client, a text editor, and a terminal. On macOS and Linux, use Terminal; on current Windows versions, use Windows Terminal or PowerShell.
- Website files and a backup copy. For a dynamic application, also know its runtime, database, and deployment requirements before installing anything.
Step-by-Step
- Create the server. In your VPS provider’s control panel, create a virtual machine with a current Ubuntu Server image. Select a location and resources appropriate for the site, and add your SSH public key if the setup offers that option. Record the IP address. Do not expose database or administration ports to the public unless you have a specific, secured need.
- Connect over SSH. From your computer, run
ssh username@SERVER_IP, replacing the placeholders with the account and IP supplied by the provider. For Ubuntu images, the initial account is oftenubuntu, but check the provider’s instructions. If prompted to confirm the host key on the first connection, verify it against the provider’s console or documentation when possible, then accept it. Never paste your private SSH key into the server or share it. - Update the operating system. Run
sudo apt update, thensudo apt upgrade. Review the changes and confirm when prompted. If the update reports that a reboot is needed, runsudo reboot, wait for the server to restart, and reconnect. Regular security updates are essential because an internet-facing server receives unsolicited connection attempts. - Set up a non-root administrator. If you are logged in as root, create a named account with
adduser yourname, then grant administrative access withusermod -aG sudo yourname. Add your public SSH key to that account’s~/.ssh/authorized_keysand set appropriate ownership and permissions. Open a second terminal and confirm you can log in and runsudobefore ending the original session. Do not disable password login or root access until key-based access is confirmed and you know how to recover through the provider console. - Allow only the required network traffic. Configure the provider’s firewall, if available, to allow inbound SSH on the port you use, plus TCP ports 80 and 443 for web traffic. On Ubuntu, you can also use UFW: first allow SSH with
sudo ufw allow OpenSSH, then allow web traffic withsudo ufw allow 'Nginx Full'after installing Nginx, and enable it withsudo ufw enable. Checksudo ufw status. Avoid enabling a firewall before allowing your SSH connection, or you could lock yourself out. Provider firewalls and UFW are separate controls; check both. - Install Nginx. Run
sudo apt install nginx, then check that it is running withsystemctl status nginx. From a browser, visithttp://SERVER_IP. The default Nginx page means the server is responding. If it does not load, confirm the service is active and that port 80 is allowed in both firewalls. - Point your domain at the VPS. In the DNS control panel for your domain, create an A record for the domain (often written
@) with the VPS IPv4 address. Add awwwrecord if you want that name too; it can be a CNAME pointing to the root domain, or an A record to the same IP. For IPv6, publish an AAAA record only if the VPS is configured to serve the site over IPv6. DNS changes can take time to appear, and cached records may persist. Check resolution before proceeding. - Put your site files on the server. Create a web directory such as
/var/www/example.com/html, then upload your site using a secure method such asscpor an authenticated deployment process. Set ownership and permissions so Nginx can read the files but unrelated users cannot modify them. For example, use a dedicated deployment account and grant the web server read access; avoid making the directory world-writable withchmod 777. - Configure the website. Create an Nginx server block in
/etc/nginx/sites-available/example.com. Setserver_nameto your domain androotto the site directory; for a static site, specifyindex index.html. Enable it with a symlink in/etc/nginx/sites-enabled/, then runsudo nginx -t. Only if the test succeeds, reload Nginx withsudo systemctl reload nginx. Do not remove the default site until the new configuration works. - Enable HTTPS and verify. Once the domain resolves to the VPS and port 80 is reachable, install Certbot and its Nginx integration using the Ubuntu package instructions for your release. Run Certbot for each hostname and follow its prompts to request a certificate and configure HTTPS. Confirm the site loads at
https://without a certificate warning, and check that renewal is scheduled using Certbot’s documented test command. Keep port 443 open. - Plan ongoing care. Keep the operating system and application dependencies patched, back up both files and databases, and test that you can restore a backup. Monitor disk space, memory, and service availability. A VPS is your responsibility to maintain; a working homepage alone does not mean backups, updates, or application security are covered.
Common Mistakes
- Opening the wrong ports, or enabling a firewall before allowing SSH. Check the provider firewall and server firewall separately.
- Editing Nginx configuration without running
nginx -t. A syntax error can prevent reloads; test first and keep a working configuration available. - Requesting HTTPS before DNS points to the VPS or port 80 is reachable. Certificate validation will fail until those conditions are met.
- Using broad file permissions such as
777, leaving default passwords in place, or exposing a database port unnecessarily. - Assuming DNS changes are instant or that an IP-only site will automatically receive a trusted certificate. Certificates are issued for domain names, not a substitute for DNS setup.
Tips
- Make one change at a time and record commands and configuration edits so you can undo a faulty change.
- Keep a second SSH session open while changing access or firewall settings. Confirm a new login works before closing the existing session.
- Use a staging hostname or test page before deploying important changes. Check both the root domain and
wwwif you configure both. - Automate repeatable deployments and backups only after you understand how to verify their results. A backup that has never been restored is not proven.
Troubleshooting
- SSH times out: Confirm the IP address, server status, SSH port, and provider firewall rules. If you changed UFW, use the provider’s web console to restore SSH access.
- Browser says the site cannot be reached: Check DNS records and allow ports 80 and 443 in both firewall layers. Test Nginx locally with
curl -I http://localhostfrom the server. - You see the default Nginx page: Check that the server block is enabled, its
server_namematches the requested hostname, and its root directory contains the expected index file. Runsudo nginx -tand inspect/var/log/nginx/error.log. - HTTPS setup fails: Verify the domain resolves to this server, the hostname is included in the certificate request, and inbound port 80 is accessible for validation. Review Certbot’s error output before trying again.
- Changes do not appear: Confirm you uploaded files to the configured document root, check file ownership, and clear your browser cache. DNS caching can also delay domain changes; compare the result from another network or DNS lookup tool.
Frequently Asked Questions
Can I host a site without a domain?
Yes. You can visit the VPS by IP address for testing, but a domain is more practical for visitors and is generally needed for a standard trusted HTTPS certificate.
How much RAM does a web-hosting VPS need?
It depends on the operating system, application, traffic, and database. A static site can run with modest resources; dynamic applications need room for their runtime and workload. Monitor usage and resize if necessary.
Do I need a control panel?
No. Nginx can be configured from the command line. A control panel may simplify routine tasks, but it adds software that also needs updates and security management.
Is Nginx the only option?
No. Apache and other web servers can host sites too. Choose one approach and follow its configuration instructions; avoid installing multiple servers that compete for the same ports.
How do I host a dynamic application?
Install the runtime and application dependencies the site requires, run the app as a restricted service account, and configure Nginx as a reverse proxy if appropriate. Keep secrets out of public web directories and expose only necessary services.
What should I back up?
Back up website files, configuration, application data, and databases. Store copies separately from the VPS and periodically test restoration.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.