Skip to content

Commit d0bee00

Browse files
authored
Merge pull request #3 from kumarmuthu/custom-http-server_03
Added MIME types and Max OS support
2 parents 1728253 + b949c73 commit d0bee00

File tree

5 files changed

+488
-110
lines changed

5 files changed

+488
-110
lines changed

README.md

Lines changed: 139 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@
22

33
![Python](https://img.shields.io/badge/python-3.x-blue.svg)
44
![License](https://img.shields.io/badge/license-MIT-green.svg)
5-
![Platform](https://img.shields.io/badge/platform-linux-lightgrey.svg)
5+
![Platform](https://img.shields.io/badge/platform-linux%20%7C%20macOS-lightgrey.svg)
66

7-
A lightweight, Python-based **Custom HTTP Server** that runs as a Linux systemd service. This project is ideal for serving static files, logs, test results, or building RESTful APIs with no external dependencies.
7+
A lightweight, Python-based **Custom HTTP Server** that runs as a **Linux systemd service** or a **macOS `launchd` agent**. Ideal for serving static files, logs, test results, or internal documentation.
8+
This is a minimal yet powerful **custom HTTP server** written in pure Python. It includes MIME-type awareness and seamless integration with **systemd (Linux)** and **launchd (macOS)** for automatic startup on boot.
89

9-
This is a minimal yet powerful **custom HTTP server** written in pure Python. It includes MIME-type awareness and seamless systemd integration for automatic startup.
10+
---
11+
12+
## ✅ Features
1013

11-
## Features
14+
- **Pure Python** (no external dependencies)
15+
- Serves any local directory
16+
- MIME-type aware (e.g., `.log`, `.tap`, `.xml`, `.html`, `.pdf`, `.md`, etc.)
17+
- Works as:
18+
- A **systemd service** on Linux
19+
- A **launchd agent** on macOS
20+
- Runs on startup
21+
- Configurable via a simple config or plist
1222

13-
- Written in **pure Python** using `http.server` (Python 3.x)
14-
- Serves any directory (configured via `/etc/custom-http-server.conf`)
15-
- Auto-starts on boot
16-
- MIME types for `.log`, `.tap`, `.xml`, `.html`
23+
---
1724

18-
## Installation
25+
## 🐧 Linux Installation (Systemd Service)
1926

2027
```bash
2128
git clone https://github.com/kumarmuthu/custom-http-server.git
@@ -26,134 +33,208 @@ sudo ./install.sh
2633

2734
---
2835

29-
* To allow users to easily update the **port** and **path** used by the custom HTTP server, you’ve already provided a config file (`/etc/custom-http-server.conf`). Here's how they can update the **port** specifically:
30-
31-
## Step-by-Step: Update Port
36+
### 🔧 Configure Port and Directory
3237

33-
1. **Open the config file:**
38+
Edit the config file:
3439

3540
```bash
3641
sudo vi /etc/custom-http-server.conf
3742
```
3843

39-
2. **Change the value of `SERVE_PORT`:**
40-
41-
You're currently using port `80`, so your config will look like:
44+
Example:
4245

4346
```ini
4447
# Path to serve (change this to your target directory)
4548
SERVE_PATH=/root
4649
SERVE_PORT=80
4750
```
4851

49-
> ℹ️ **Note:** Port `80` is the default HTTP port and requires the service to run as **root**. This is already handled by the systemd unit (`User=root`), so no additional configuration is required for privileged port access.
50-
51-
> For non-root ports like `8080` or `8000`, you can freely change the `SERVE_PORT` without needing elevated permissions.
52+
* Port `80` requires **root** privileges (already handled by systemd).
53+
* You can use any non-privileged port like `8080`, `8000`, etc., without root.
5254

53-
3. **Save and exit**
54-
55-
4. **Restart the service to apply changes:**
55+
Restart to apply changes:
5656

5757
```bash
5858
sudo systemctl restart custom-http-server
5959
```
6060

6161
---
6262

63-
### Verify the Port
64-
65-
You can check whether the server is now running on port 80:
63+
### ✅ Verify
6664

6765
```bash
68-
sudo lsof -i :80
69-
```
70-
71-
Or access it via:
72-
73-
```
74-
http://<your-ip>/
66+
sudo systemctl status custom-http-server
67+
sudo lsof -i :80 # Or your configured port
7568
```
7669

77-
---
78-
7970
Check service status to confirm it's running properly:
8071

8172
```bash
8273
sudo systemctl status custom-http-server
8374
```
8475

85-
## Logs
76+
---
77+
78+
### 📜 Logs
8679

8780
```bash
8881
sudo journalctl -u custom-http-server -f
8982
```
9083

9184
---
9285

93-
## Open Port 80 for Web Access
86+
### 🔓 Allow Port in Firewall
9487

95-
### On **Rocky Linux** (uses `firewalld`):
88+
#### On **Rocky Linux**:
9689

9790
```bash
9891
sudo firewall-cmd --permanent --add-port=80/tcp
9992
sudo firewall-cmd --reload
10093
```
10194

102-
**Verify the port is open:**
95+
#### On **Ubuntu**:
10396

10497
```bash
105-
sudo firewall-cmd --list-ports
98+
sudo ufw allow 80/tcp
99+
sudo ufw reload
106100
```
107101

108102
---
109103

110-
### On **Ubuntu** (typically uses `ufw`):
104+
### ❌ Uninstall (Linux)
111105

112106
```bash
113-
sudo ufw allow 80/tcp
114-
sudo ufw reload
107+
cd custom-http-server/custom-http-server
108+
sudo ./uninstall.sh
109+
```
110+
111+
---
112+
113+
## 🍏 macOS Installation (launchd Agent)
114+
115+
```bash
116+
git clone https://github.com/kumarmuthu/custom-http-server.git
117+
cd custom-http-server/custom-http-server
118+
chmod +x install.sh uninstall.sh macos-launchd-setup.sh
119+
sudo ./install.sh -path /Users/<username> -port 8080
115120
```
116121

117-
**Verify UFW status and rules:**
122+
* `--path` → Directory to serve
123+
* `--port` → HTTP port to use (e.g., 8080)
124+
125+
The script installs a `launchd` service and autostarts it.
126+
127+
---
128+
129+
### ✅ Verify & Logs (macOS)
130+
131+
Check if service is running:
118132

119133
```bash
120-
sudo ufw status
134+
launchctl list | grep custom_httpserver
121135
```
122136

123-
Or:
137+
Watch logs in real time:
124138

125139
```bash
126-
sudo ufw show
140+
watch "cat /tmp/custom_httpserver.log"
127141
```
128142

129-
> **Note:** `firewalld` is not installed by default on Ubuntu. It usually uses `ufw` (Uncomplicated Firewall).
143+
Example `.log` log:
144+
145+
```
146+
muthukumar@muthukumar custom-http-server % cat /tmp/custom_httpserver.log
147+
#########Script Start#########
148+
Resolved serve path:/root /root
149+
Observed exception is: Invalid directory: /root
150+
##########Script End##########
151+
#########Script Start#########
152+
Resolved serve path:/U /U
153+
Observed exception is: Invalid directory: /U
154+
##########Script End##########
155+
#########Script Start#########
156+
Resolved serve path:/Users /Users
157+
Observed exception is: [Errno 48] Address already in use
158+
##########Script End##########
159+
#########Script Start#########
160+
Resolved serve path:/Users/muthukumar /Users/muthukumar
161+
Observed exception is: [Errno 48] Address already in use
162+
##########Script End##########
163+
muthukumar@muthukumar custom-http-server %
164+
```
165+
166+
Or **error** logs:
167+
168+
```bash
169+
watch "cat /tmp/custom_httpserver.err"
170+
```
171+
172+
Example `.err` log:
173+
174+
```
175+
muthukumar@muthukumar custom-http-server % cat /tmp/custom_httpserver.err
176+
10.138.237.56 - - [21/Jun/2025 02:15:19] "GET /Documents/ HTTP/1.1" 200 -
177+
10.138.237.56 - - [21/Jun/2025 02:15:20] "GET /Documents/ HTTP/1.1" 200 -
178+
10.138.237.56 - - [21/Jun/2025 02:15:21] "GET /Documents/Screenshot%202024-12-06%20at%202.21.59%E2%80%AFPM.png HTTP/1.1" 200 -
179+
127.0.0.1 - - [21/Jun/2025 02:23:27] "GET / HTTP/1.1" 200 -
180+
10.138.237.56 - - [21/Jun/2025 02:23:31] "GET /Documents/ HTTP/1.1" 200 -
181+
10.138.237.56 - - [21/Jun/2025 02:23:32] "GET /Documents/AMD/ HTTP/1.1" 200 -
182+
10.138.237.56 - - [21/Jun/2025 02:23:35] "GET /Documents/AMD/Ubuntu%20VM%20OS%20install.txt HTTP/1.1" 200 -
183+
10.138.237.56 - - [21/Jun/2025 02:29:02] "GET /Documents/AMD/Ubuntu%20VM%20OS%20install.txt HTTP/1.1" 304 -
184+
10.138.237.56 - - [21/Jun/2025 02:29:05] "GET /Documents/AMD/Nutanix_Int_session.txt HTTP/1.1" 200 -
185+
10.138.237.56 - - [21/Jun/2025 02:36:41] "GET /Documents/AMD/Notes5.1.txt HTTP/1.1" 200 -
186+
10.138.237.56 - - [21/Jun/2025 02:42:41] "GET /Documents/ HTTP/1.1" 200 -
187+
10.138.237.56 - - [21/Jun/2025 02:42:43] "GET /Documents/Nutanix/ HTTP/1.1" 200 -
188+
10.138.237.56 - - [21/Jun/2025 02:42:45] "GET /Documents/Nutanix/Notes5.txt HTTP/1.1" 200 -
189+
10.138.237.56 - - [21/Jun/2025 02:45:10] "GET /Documents/Nutanix/Install_java.txt HTTP/1.1" 200 -
190+
10.138.237.56 - - [21/Jun/2025 03:12:54] "GET / HTTP/1.1" 200 -
191+
10.138.237.56 - - [21/Jun/2025 03:12:54] code 404, message File not found
192+
10.138.237.56 - - [21/Jun/2025 03:12:54] "GET /favicon.ico HTTP/1.1" 404 -
193+
10.138.237.56 - - [21/Jun/2025 03:42:44] "GET / HTTP/1.1" 200 -
194+
10.138.237.56 - - [21/Jun/2025 03:42:47] "GET /Documents/ HTTP/1.1" 200 -
195+
muthukumar@muthukumar custom-http-server %
196+
```
130197

131198
---
132199

133-
## Uninstall:
134-
To completely remove the HTTP server:
135-
```bash
136-
cd custom-http-server/custom-http-server
137-
sudo ./uninstall.sh
138-
```
200+
### ❌ Uninstall (macOS)
201+
202+
Manually remove the background service:
203+
204+
```bash
205+
launchctl unload ~/Library/LaunchAgents/com.custom_http_server.plist
206+
rm -f ~/Library/LaunchAgents/com.custom_http_server.plist
207+
launchctl list | grep custom_httpserver # ✅ Should return nothing
208+
```
209+
210+
Or use the provided uninstallation script:
211+
212+
```bash
213+
cd custom-http-server/custom-http-server
214+
sudo ./uninstall.sh
215+
```
139216

140217
---
141218

142219
## ✅ Final Notes
143-
- Built entirely in **Python 3** (no external dependencies)
144-
- Users can easily change the served directory in `/etc/custom-http-server.conf`.
145-
- The Python file and config get copied to `/opt` and `/etc`, making the systemd unit generic.
220+
221+
* Works on **Linux (systemd)** and **macOS (launchd)**
222+
* Built with **pure Python 3**
223+
* No external dependencies
224+
* Easily configurable
146225

147226
---
148227

149228
## License
150229

151-
This project is licensed under the [MIT License](https://opensource.org/licenses/MIT).
230+
This project is licensed under the [MIT License](https://opensource.org/licenses/MIT).
152231
You are free to use, modify, and distribute it with attribution.
153232

233+
---
234+
154235
## Author
155236

156-
Developed and maintained by [Muthukumar S]
237+
Developed and maintained by \[Muthukumar S]
157238
GitHub: [https://github.com/kumarmuthu/](https://github.com/kumarmuthu/)
158239

159240
---

0 commit comments

Comments
 (0)