How to operate multiple services on a single server
Introduction
As an indie hacker, I have been operating multiple services and trying to monetize them, but the cost of using AWS servers has been a burden. While looking for a cheaper alternative, I decided to utilize a gaming PC that was not being used at home as a server.
This PC was purchased about 5 years ago for around 2 million won, and to use the same specifications on AWS, it would cost at least 600,000 won per month. Furthermore, most of the services I operate have very few users and hardly use any traffic. In that case, could I efficiently operate multiple services using Docker on this server?
Configuration
It is easier to understand when approached step by step. Let's first look at the most basic configuration.
1. Running multiple services with Docker on an Ubuntu server
-
Run each service as a Docker container on an Ubuntu server.
-
Distribute traffic appropriately using Nginx.
-
With just this, it is possible to operate services at the level of an internal network without external access.
2. Service differentiation using Nginx
-
By using the server_name in the Nginx configuration file to separate each service, you can route traffic to the appropriate Docker container.
-
Example configuration:
3. Setting up external access via IP
- To directly access the server from outside, you need to connect a public IP to the server.
- If using a router, set up port forwarding to direct external traffic to the server.
- Example setup: Forward ports 80 and 443 from the router to the server.
4. Domain connection (using AWS Route 53, etc.)
- By using services like AWS Route 53, you can use a domain address instead of an IP.
- Set the A record in the DNS settings to the public IP of the home network.
5. Using CNAME for IP changes
- If you don't have a static IP, you can easily adapt to IP changes by using CNAME records.
- For example, by connecting api.example.com to myserver.example.com (a fixed domain), you only need to modify the A record of myserver.example.com when the actual IP changes.
6. Applying HTTPS (using Let’s Encrypt)
-
By using Let’s Encrypt, you can obtain SSL certificates for free.
-
Setting up automatic renewal with Certbot allows you to maintain a secure HTTPS environment without additional costs.
-
Basic SSL configuration example:
server { listen 443 ssl; server_name example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; }
Conclusion
Although I did not cover all the detailed settings here, I wanted to show that it is entirely possible to use a local PC as a server to save costs.
While AWS offers excellent scalability and reliability, the initial cost is high. On the other hand, by utilizing a local PC, you can operate multiple services directly while saving costs.
This method is suitable for personal projects or small-scale service operations. Initially operating in this way and then expanding to a cloud environment like AWS when traffic increases and revenue is guaranteed seems like a good strategy.
