HTTP Accessiable in VM
🧩 Goal
आपके पास Linux server (VM1) है जिसमें PDF files रखे हैं,
और आप चाहते हैं कि दूसरी VM (VM2) उन files को HTTP से access कर सके, जैसे:
http://192.168.1.10:8080/files/sample.pdf
✅ Option 1 — Simple HTTP Server (Fastest Setup)
🪶 Step 1: Directory बनाएं और PDF डालें
mkdir -p /home/ecitizen/files
cd /home/ecitizen/files
अब अपनी PDF फाइल इस folder में रख दें:
cp /path/to/sample.pdf /home/ecitizen/files/
🪶 Step 2: Python से HTTP सर्वर चलाएँ
अगर Python इंस्टॉल है (अधिकांश Linux में पहले से होता है):
cd /home/ecitizen/files
python3 -m http.server 8080
अब आपका server चल गया ✅
ब्राउज़र या दूसरी VM से खोलिए:
http://<VM1-IP>:8080/sample.pdf
Example:
http://192.168.1.10:8080/sample.pdf
🧠 Note:
अगर आप चाहते हैं कि यह background में चले:
nohup python3 -m http.server 8080 --directory /home/ecitizen/files > server.log 2>&1 &
🔥 Firewall खुला रखें:
यदि firewall enable है (Ubuntu में ufw या CentOS में firewalld):
sudo ufw allow 8080
# या
sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --reload
✅ Option 2 — NGINX से Host करना (Permanent Setup)
अगर आपको production-level stability चाहिए
(उदाहरण: Spring Boot app के साथ stable hosting),
तो NGINX use करें।
🪶 Step 1: Install NGINX
sudo apt update
sudo apt install nginx -y
🪶 Step 2: Folder बनाइए
sudo mkdir -p /var/www/pdffiles
sudo cp /home/ecitizen/files/*.pdf /var/www/pdffiles/
🪶 Step 3: NGINX configuration बनाइए
sudo nano /etc/nginx/sites-available/pdfserver
फ़ाइल में डालें 👇
server {
listen 8080;
server_name _;
location /files/ {
alias /var/www/pdffiles/;
autoindex on;
}
}
🪶 Step 4: Enable site
sudo ln -s /etc/nginx/sites-available/pdfserver /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
🧩 अब access करें:
http://192.168.1.10:8080/files/sample.pdf
✅ आप सीधे Java या browser से PDF file access कर सकते हैं।
✅ Option 3 — Spring Boot से Serve करना (अगर VM1 पर Spring चल रहा है)
अगर VM1 में आपका Spring Boot project चल रहा है
तो resources/static/files/ folder बनाइए
और PDF वहीं डालिए:
src/main/resources/static/files/sample.pdf
फिर Spring Boot चलाइए —
अब file URL से खुलेगा:
http://192.168.1.10:8080/files/sample.pdf
⚙️ Summary Comparison
| तरीका | Time | स्थायित्व | Best for |
python3 -m http.server | ⏱️ 1 min | ❌ Temporary | Testing / Quick Access |
NGINX | ⏱️ 10 min | ✅ Permanent | Production |
Spring Boot static | ⏱️ 5 min | ✅ With App | Application Integration |