This guide shows how to configure the HTTP Proxy to run automatically as a service on Linux using systemd.
Create a file named proxy.service in /etc/systemd/system/:
[Unit]
Description=HTTP Proxy Server (Node.js)
After=network.target
[Service]
User=exampleuser
WorkingDirectory=/path/to/http-proxy
EnvironmentFile=/path/to/file/.env
ExecStart=path/to/bin/node /path/to/http-proxy/dist/index.js
Restart=on-failure
RestartSec=10
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.targetNote:
- Adjust the paths according to your environment (user, project directory, Node.js version).
- The
EnvironmentFileline ensures that variables from.envare loaded.
sudo systemctl daemon-reload
sudo systemctl enable proxy.service
sudo systemctl start proxy.serviceWith the StandardOutput=journal and StandardError=journal options, view real-time logs with:
sudo journalctl -u proxy.service -fTo ensure the service restarts every 2 hours, add this line to the root user's crontab:
0 */2 * * * /bin/systemctl restart proxy.serviceEdit the root crontab with:
sudo crontab -e- To check the service status:
sudo systemctl status proxy.service
- To restart manually:
sudo systemctl restart proxy.service
Done! Your proxy will now run automatically as a service on Linux.