Cloud Computing

How to Troubleshoot a Website That Goes Down After a Server Restart

A website that stops working after a server restart can cause unexpected downtime, lost visitors, and business disruptions. This issue often occurs when…

D
DevByteTechnical Author
Published
17 min read3 views
How to Troubleshoot a Website That Goes Down After a Server Restart

Have you ever restarted your server expecting everything to work normally, only to discover that your website is no longer accessible?

Maybe your React frontend loads, but the API returns a 502 Bad Gateway error. Maybe your Node.js application was working perfectly before the restart, but now it refuses to start. Or perhaps your website opens normally for a few minutes before suddenly going down again.

These problems are more common than you might think, especially when hosting applications on a VPS, a Linux server, or a cloud virtual machine.

The confusing part is that restarting a server should not normally break a properly configured application. If your website stops working afterward, something may not be starting automatically, a service may be failing, or the application may depend on a process that was only running temporarily.

For example, you might have started your Node.js application manually using npm start. Everything worked until the server restarted. After rebooting, Linux came back online, but your Node.js process did not.

The same problem can happen with MongoDB, Redis, Nginx, Docker containers, or environment variables.

In this guide, we will walk through how to troubleshoot a website that goes down after a server restart, identify the most common causes, and fix the underlying problems instead of repeatedly restarting the server.

1. First, Understand What Actually Goes Down

Before changing any configuration, identify which part of your application is failing.

A typical web application might look like this:

                  User's Browser
                        |
                        v
                   Domain / DNS
                        |
                        v
                  Nginx Web Server
                        |
                        v
                 Node.js / Express
                        |
                        v
                 MongoDB / Redis

Each component has a different responsibility.

  • DNS directs visitors to the correct destination.

  • Nginx receives HTTP and HTTPS requests and may forward them to your application.

  • Node.js runs your backend code.

  • MongoDB stores application data.

  • Redis may handle caching, sessions, queues, or temporary data.

If any required component fails to start after a reboot, the entire website or some of its features may stop working.

For example, Nginx might be running correctly, but it cannot reach your Node.js application. In that situation, visitors may see a 502 Bad Gateway error.

Alternatively, the API might be running, but it cannot connect to MongoDB. Your homepage could still load while login, registration, and other database-related features fail.

The first rule of troubleshooting is simple: identify the failing component before trying to fix it.

2. Check Whether the Server Is Actually Running

Start with the basics.

If your website is hosted on a VPS or cloud virtual machine, confirm that the server is running and reachable.

Connect through SSH:

ssh username@your-server-ip

Replace the example username and IP address with your actual server details.

Once connected, check the system's uptime:

uptime

This shows how long the server has been running, along with its load averages.

You can also check the current date and time:

date

The date can be useful when comparing system logs with the time your website went down.

Next, inspect available memory and disk space:

free -h
df -h

The first command displays memory usage. The second shows filesystem usage.

Why do these commands matter?

Suppose your server runs out of disk space because logs have grown too large. Your application may fail to write files, update temporary data, or start correctly.

Similarly, if the server has very little available memory, a process may be terminated under memory pressure.

Check the current processes:

top

If available, you can also use:

htop

The second command requires htop to be installed.

Look for unusually high CPU or memory usage, but do not assume that high usage is automatically the cause. Compare what you see with the application's logs and service status.

If the server is running and you can connect through SSH, move on to checking the application services.

3. Check Whether Nginx Is Running

Many applications use Nginx as a reverse proxy.

Nginx receives requests from visitors and forwards them to a backend application running on an internal port, such as 3000.

If Nginx fails to start after a reboot, visitors may be unable to reach your website even when the Node.js application is running.

Check its status:

sudo systemctl status nginx

You may see one of several states:

  • active (running): Nginx is running.

  • inactive (dead): The service is not currently running.

  • failed: Nginx attempted to start but encountered a problem.

If Nginx is stopped and you expect it to be running, start it:

sudo systemctl start nginx

Then check the status again:

sudo systemctl status nginx

If the service is running but your website still does not work, validate the configuration:

sudo nginx -t

This command checks the Nginx configuration for syntax errors and related problems.

If the test succeeds, reload the configuration when appropriate:

sudo systemctl reload nginx

If Nginx cannot start, inspect its logs:

sudo journalctl -u nginx -b --no-pager

You can also inspect the error log:

sudo tail -n 100 /var/log/nginx/error.log

Look for messages about invalid configuration, unavailable upstream services, permission problems, or ports that are already in use.

Do not immediately reinstall Nginx or replace its configuration. The logs usually provide a better starting point.

4. Check Whether Your Node.js Application Is Running

This is one of the most common causes of websites going down after a server restart.

Imagine that you deployed a Node.js application and started it using:

npm start

The application starts successfully, and visitors can use the website.

However, when the server restarts, the process is gone.

The reason is that a process started manually from your terminal is not automatically guaranteed to restart when Linux boots.

Unless you have configured a process manager or service manager, your application may remain stopped after the reboot.

Check the application process

You can look for running Node.js processes:

ps aux | grep '[n]ode'

This can help you determine whether a Node.js process is currently running.

However, seeing a Node.js process does not guarantee that your application is healthy. It might be running but unable to connect to its database or serve requests correctly.

Next, check which processes are listening on the expected application port:

sudo ss -ltnp

If your application should listen on port 3000, look for a listener on that port.

You can also test the application locally from the server:

curl -i http://127.0.0.1:3000/

Replace the port and path with the values used by your application.

If the request fails, the backend may not be running, may be listening on a different address or port, or may be failing during request processing.

If the local request works but the public website does not, investigate Nginx, networking, DNS, or HTTPS configuration.

5. Use PM2 to Keep Your Node.js Application Running

If you run a Node.js application on a VPS, a process manager such as PM2 can help manage the application lifecycle.

PM2 can start your application in the background, restart it after certain failures, and restore saved processes when the server reboots.

First, install PM2 if it is not already installed:

npm install -g pm2

Navigate to your project directory:

cd /var/www/my-app

Start the application:

pm2 start npm --name my-app -- start

This tells PM2 to run the project's npm start command and manage the process under the name my-app.

Check the process list:

pm2 status

View application logs:

pm2 logs my-app

If the application is stopped, you can restart it:

pm2 restart my-app

These commands help manage the application, but there is one additional step if you want it to return automatically after a server reboot.

Configure PM2 startup

Run:

pm2 startup

PM2 will display a command tailored to your system. Run the command it provides, using the appropriate privileges.

Then save the current process list:

pm2 save

The saved process list allows PM2 to restore the configured applications when its startup integration runs.

For example, your workflow may look like this:

pm2 start npm --name my-app -- start
pm2 save
pm2 startup

The exact order matters less than ensuring that you complete the setup: generate the startup configuration, execute the command PM2 provides, and save the processes you want restored.

After configuration, test the setup during a maintenance window or another safe opportunity.

Important: PM2 helps restart processes, but it does not fix application errors automatically. If your application crashes because of invalid configuration, a missing environment variable, or a failed database connection, you still need to fix the underlying problem.

Official documentation: https://pm2.keymetrics.io/docs/usage/startup/

6. Consider systemd for More Controlled Application Management

PM2 is popular in the Node.js ecosystem, but Linux also provides systemd, which can manage long-running services.

For applications that you want to run as operating-system services, a systemd unit is another option.

For example, create a service file:

sudo nano /etc/systemd/system/my-app.service

Add a configuration similar to this:

[Unit]
Description=My Node.js Application
After=network.target

[Service]
Type=simple
User=www-data
WorkingDirectory=/var/www/my-app
Environment=NODE_ENV=production
ExecStart=/usr/bin/npm start
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

This is an example, not a configuration you should copy without checking your environment.

Make sure that:

  • www-data is an appropriate user for your application.

  • The project directory exists and is accessible to that user.

  • The npm executable is available at the specified path.

  • Your application's start command is correct.

  • Required environment variables and secrets are configured securely.

If your application uses a Node.js version managed through NVM, the executable paths and environment may differ from a system-wide Node.js installation. In that case, adjust the service configuration accordingly.

After saving the file, reload the service definitions:

sudo systemctl daemon-reload

Enable the service at boot:

sudo systemctl enable my-app

Start it:

sudo systemctl start my-app

Check its status:

sudo systemctl status my-app

If the application fails, inspect the logs:

sudo journalctl -u my-app -b --no-pager

You can also follow new log messages:

sudo journalctl -u my-app -f

The Restart=on-failure setting tells systemd to restart the service when it exits unsuccessfully, subject to systemd's restart rules and limits.

Choose either PM2 or systemd based on your deployment requirements. You generally do not need both managing the same application process.

7. Check MongoDB and Redis After the Restart

Sometimes the backend is running, but the application still fails because its dependencies are unavailable.

For example, your Node.js application may start and immediately attempt to connect to MongoDB.

If MongoDB is stopped, the application may throw an error, fail its health checks, or repeatedly attempt to reconnect.

Check MongoDB

If MongoDB is installed as a system service, check its status:

sudo systemctl status mongod

If the service is stopped and you expect it to run locally:

sudo systemctl start mongod

Check its logs:

sudo journalctl -u mongod -b --no-pager

The service name and commands may differ depending on how MongoDB was installed and configured.

If you use MongoDB Atlas or another managed database, checking the local mongod service is not appropriate. Instead, check network connectivity, credentials, access rules, and the managed database's status.

Check Redis

If Redis runs locally as a service, inspect it:

sudo systemctl status redis-server

On some systems, the service may be named redis instead.

If the service is stopped, inspect the logs before deciding how to restart it:

sudo journalctl -u redis-server -b --no-pager

If you use a hosted Redis service, check the provider's dashboard and connection configuration instead.

Make your application handle dependency failures

Your Node.js application should handle database connection failures deliberately.

For example, with Mongoose:

import mongoose from "mongoose";

async function connectDatabase() {
  try {
    await mongoose.connect(process.env.MONGODB_URI);
    console.log("MongoDB connected");
  } catch (error) {
    console.error("MongoDB connection failed:", error.message);
    process.exit(1);
  }
}

connectDatabase();

This is a simplified example. If the application depends on MongoDB to serve requests, exiting with a failure code can allow a process manager to restart it.

However, repeated restarts will not resolve an incorrect URI, invalid credentials, or a network restriction. Make sure your logs clearly identify the problem, and avoid creating a restart loop that hides the underlying failure.

For more resilient applications, consider explicit readiness checks, appropriate retry strategies, and graceful shutdown handling.

8. Check Environment Variables and Configuration Files

Another common problem is that the application works before a restart but fails afterward because its environment was not configured correctly.

Consider this code:

const port = process.env.PORT || 3000;
const mongoUri = process.env.MONGODB_URI;

The application expects environment variables to be available.

During development, those variables might come from a local .env file. In production, they may be supplied through a process manager, service configuration, deployment dashboard, or secret-management system.

If the application starts under a different user or service manager after rebooting, it might not receive the same environment variables.

This can lead to errors such as:

  • MONGODB_URI is not defined.

  • Authentication failures.

  • Missing API keys.

  • Incorrect application ports.

  • Failed connections to Redis or external services.

How to troubleshoot environment variables

First, inspect the application logs.

Then verify that the required variables are configured in the environment used by the actual service.

For a systemd service, you might use an environment file:

[Service]
EnvironmentFile=/etc/my-app/my-app.env

The referenced file must exist and have appropriate permissions. Its syntax must also match systemd's environment-file format.

Protect the file so that only authorized users can read it.

For PM2, configure the environment through the supported ecosystem configuration or another secure deployment mechanism.

Avoid printing secrets directly into logs or pasting complete environment files into public issue trackers.

Also, do not assume that a .env file is automatically loaded just because it exists in your project directory. Your application must explicitly load it, or the deployment environment must supply the values.

9. Troubleshoot a 502 Bad Gateway Error

A 502 Bad Gateway error often appears when Nginx is acting as a reverse proxy but cannot obtain a valid response from the backend.

Suppose your Nginx configuration contains:

location /api/ {
    proxy_pass http://127.0.0.1:3000;
}

This configuration expects the backend to be reachable on the specified address and port.

If Node.js does not start after the server restarts, Nginx may return a 502 response.

Here is a practical troubleshooting sequence.

Step 1: Check Nginx.

sudo systemctl status nginx

Step 2: Check the backend process.

pm2 status

If you use systemd, check the corresponding application service instead.

Step 3: Test the backend directly.

curl -i http://127.0.0.1:3000/

Step 4: Inspect Nginx's error log.

sudo tail -n 100 /var/log/nginx/error.log

Step 5: Inspect the backend logs.

pm2 logs my-app

These checks help narrow down the problem.

If the backend is unavailable, fix its startup or configuration. If it responds locally but Nginx still fails, verify the proxy destination, port, network binding, and Nginx configuration.

Do not assume that every 502 error means the server needs more memory. The actual cause may be much simpler.

10. Check Whether Your Application Is Listening on the Correct Port

A Node.js application might start successfully but listen on a different port than Nginx expects.

For example, your application might use:

const PORT = process.env.PORT || 4000;

app.listen(PORT, () => {
  console.log(`Server running on port ${PORT}`);
});

But your Nginx configuration might forward requests to port 3000.

In that case, Nginx cannot reach the backend at the configured destination.

Check the listening ports:

sudo ss -ltnp

Then compare the result with your application's configuration.

If the application is listening on port 4000, either update Nginx to use the correct port or change the application configuration to match your intended setup.

Also check the address on which Node.js listens.

For a backend accessed through a local Nginx reverse proxy, binding to 127.0.0.1 is often appropriate:

app.listen(PORT, "127.0.0.1", () => {
  console.log(`Server running on port ${PORT}`);
});

The correct binding depends on your architecture. A containerized application or a service accessed through another host may need a different configuration.

Do not expose a backend port publicly unless your deployment actually requires it.

11. Check Docker Containers and Their Restart Policies

If you deploy your application using Docker, a server restart can reveal another common issue: containers may not be configured to restart automatically.

List all containers, including stopped ones:

docker ps -a

If your application container is stopped, inspect its logs:

docker logs --tail 100 my-app

Replace my-app with your actual container name or ID.

You can start the container manually:

docker start my-app

But if you want the container to restart automatically after a Docker daemon restart or system reboot, configure an appropriate restart policy.

For example:

docker run -d \
  --name my-app \
  --restart unless-stopped \
  -p 3000:3000 \
  my-image

The unless-stopped policy tells Docker to restart the container automatically unless it has been explicitly stopped.

For a Docker Compose application, you can configure the service similarly:

services:
  app:
    build: .
    ports:
      - "3000:3000"
    restart: unless-stopped

Then deploy it using your normal Compose workflow.

Be aware that a restart policy does not guarantee application health. A container can remain running while the application inside it is unable to serve requests. Health checks and application logs are still important.

If you use Docker Compose, also verify that the required dependencies are available and that the application can reconnect to them after a reboot.

12. Check DNS, HTTPS, and Firewall Rules

If the application and web server appear to be running, investigate the network path between the visitor and your application.

Start by checking DNS resolution.

You can use:

dig yourdomain.com

Or:

nslookup yourdomain.com

Compare the result with the IP address or hosting destination you expect.

If the server's public IP address changed during the restart or after a cloud infrastructure change, your DNS record might still point to an old address.

A normal reboot of a VPS with a reserved static IP should not usually change the address, but this depends on the hosting provider and how the instance is configured.

Next, test the website locally from the server:

curl -I http://127.0.0.1

If you use HTTPS, inspect the response:

curl -Iv https://yourdomain.com

These commands can help reveal connection failures, HTTP response codes, and TLS problems.

Also check the firewall and cloud networking rules.

On a Linux server using UFW, you can inspect the current rules:

sudo ufw status

For a typical public website, HTTP and HTTPS traffic must be permitted if your architecture uses those ports.

Cloud providers may also have security groups, network firewalls, or other access rules outside the operating system.

Do not disable the firewall completely just to make the website work. Identify which connection is being blocked and allow only the traffic your application needs.

13. Read the Logs Instead of Guessing

Logs are among the most useful tools when troubleshooting a website that fails after a restart.

Instead of making multiple configuration changes at once, identify the first relevant error and work backward from it.

For system services, use:

sudo journalctl -b -p err --no-pager

This displays error-priority messages from the current boot.

To inspect the previous boot, where the system retains its journal:

sudo journalctl -b -1 --no-pager

The previous boot's logs may not be available on every system, particularly if persistent journaling is not enabled.

For Nginx:

sudo tail -n 100 /var/log/nginx/error.log

For PM2:

pm2 logs my-app

For Docker:

docker logs --tail 100 my-app

For a systemd-managed application:

sudo journalctl -u my-app -b --no-pager

Look for errors that appear around the time of the restart.

For example:

  • Connection refused may indicate that a service is not listening at the expected address.

  • Address already in use may indicate a port conflict.

  • Permission denied may indicate a user or filesystem permission problem.

  • No space left on device indicates that the relevant filesystem or resource has run out of space.

  • A database authentication error suggests a credential or access problem.

These messages are clues rather than complete diagnoses. Read the surrounding logs to understand the context.

14. A Practical Troubleshooting Checklist

If your website goes down after restarting a server, follow this sequence before making major changes.

Check

Command or action

What it helps identify

Server availability

Connect through SSH

Whether the server is reachable

Memory and disk

free -h and df -h

Resource exhaustion

Nginx status

sudo systemctl status nginx

Web-server startup problems

Application status

pm2 status or systemctl status my-app

Backend process failures

Listening ports

sudo ss -ltnp

Missing listeners or port mismatches

Backend response

curl -i http://127.0.0.1:3000/

Whether the application responds locally

MongoDB status

sudo systemctl status mongod

Local database service issues

Docker status

docker ps -a

Stopped containers

Service logs

journalctl or application logs

Startup and runtime errors

DNS

dig yourdomain.com

Incorrect domain resolution

HTTPS

curl -Iv https://yourdomain.com

Connection and TLS problems

Adjust the commands to match your setup. For example, do not check a local MongoDB service if your application uses a hosted database.

Conclusion

A website that stops working after a server restart does not necessarily have a major infrastructure problem. In many cases, a required service simply failed to start automatically, the application lost access to an environment variable, or a backend dependency became unavailable.

The most important thing is to troubleshoot the application layer by layer.

Start by checking whether the server is reachable. Then verify Nginx, the Node.js process, the listening ports, and any database or cache services your application depends on. Inspect the logs before making configuration changes.

For Node.js applications running on a VPS, configure a process manager such as PM2 or use a properly configured systemd service. If you use Docker, review the container restart policies. Make sure your application receives its required environment variables and can recover from temporary dependency failures.

Finally, test the complete deployment after making changes. Confirm that the website works locally, through the reverse proxy, and through its public domain.

A reliable deployment is not just one that works before a restart. It is one that can recover correctly when the server reboots, a process crashes, or a dependency becomes temporarily unavailable.

D
DevByteAuthor

Technical author and software engineer at DevByte. Writing deep-dive tutorials on distributed systems, modern full-stack web architectures, and cloud deployments.

Keep Exploring

Related Engineering Dispatches

More guides and architectural patterns you might find valuable.

Browse All Articles↘