A Guide to Publishing a Site from Your Home Computer
Why Publish a Site from Your Home Computer?
It is an ideal solution for publishing sites from your home computer, creating quick demos and prototypes, sharing personal projects and creating a training and testing environment. However, there are some limitations: * If the computer is turned off, the site closes. * Home internet upload speed affects performance. * VPS is recommended for continuous and high traffic.
Cloudflare Tunnel Logic
Cloudflare Tunnel, traffic first comes to Cloudflare, then Cloudflare forwards it to your computer through the tunnel. In this way, the port is not opened on the modem, the IP is not written in the domain name and HTTPS comes automatically.
Overview of the Architecture
The architecture overview is as follows: * Nginx: Restoration proxy * PHP-FPM: PHP execution * Node.js: API or service * Cloudflare Tunnel: Secure exit to the outside world
Domain Names
Domain names are as follows: * site.com -> localhost:80 * api.site.com -> localhost:3000
Requirements
The requirements are as follows: * Domain name * Cloudflare account * Windows or Linux computer * Nginx * PHP-FPM * Node.js * Cloudflared
Step by Step Installation
Linux Installation
1) System Update
sudo apt update -y && sudo apt upgrade -y
2) Nginx + PHP-FPM
sudo apt install -y nginx php-fpm sudo systemctl enable nginx sudo systemctl start nginx Test: curl http://localhost
3) Node.js
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo apt install -y nodejs node -v Example service: mkdir -p ~/nodeapi cd ~/nodeapi npm init -y npm i express printf "const express=require('express');const app=express();app.get('/',(r,s)=>s.send('ok'));app.listen(3000);" > index.js node index.js
4) Nginx Reverse Proxy
sudo tee /etc/nginx/sites-available/site.com <<'EOF' server { listen 80; server_namesite.com; root /var/www/site; index index.php index.html; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php-fpm.sock; } } EOF sudo tee /etc/nginx/sites-available/api.site.com <<'EOF' server { listen 80; server_name api.site.com; location / { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; } } EOF sudo ln -s /etc/nginx/sites-available/site.com /etc/nginx/sites-enabled/site.com sudo ln -s /etc/nginx/sites-available/api.site.com /etc/nginx/sites-enabled/api.site.com sudo nginx -t sudo systemctl reload nginx
5) Cloudflared
wget -q https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb sudo dpkg -i cloudflared-linux-amd64.deb cloudflared -v
6) Tunneling
cloudflared login cloudflared tunnel create mytunnel cloudflared tunnel route dns mytunnel site.com cloudflared tunnel route dns mytunnel api.site.com `~/.cloudflared/config.yml`: tunnel: mytunnel credentials-file: /home/user/.cloudflared/benimtunnel.json ingress: - hostname: site.com service: http://localhost:80 - hostname: api.site.com service: http://localhost:3000 - service: http_status:404 cloudflared tunnel run mytunnel
Windows Setup
1) Nginx + PHP
* Download Nginx for Windows * Download PHP and configure php.ini * Run Nginx on port 80
2) Node.js
* Install Node.js * Example service:
mkdir %USERPROFILE%\nodeapi cd %USERPROFILE%\nodeapi npm init -y npm i express node -e "const express=require('express');const app=express();app.get('/',(r,s)=>s.send('ok'));app.listen(3000)"
3) Nginx Reverse Proxy (Windows)
* Add server blocks to `nginx.conf` and restart
4) Cloudflared
* Cloudflared Windows binary download * Sample commands:
cloudflared -v cloudflared login cloudflared tunnel create mytunnel cloudflared tunnel route dns mytunnel site.com cloudflared tunnel route dns mytunnel api.site.com cloudflared tunnel run mytunnel
HTTPS and Security
HTTPS comes automatically, IP is hidden, and basic WAF and DDoS protection is enabled. Additional recommendations: * Keep admin panels on subdomain * Add token verification for API * Apply Nginx rate limit
Performance
Performance is the determinant of upload speed. UPS is recommended for 24/7 use.
FAQ
* Will I enter an IP address? No * Will I open a port? No * Is it possible without my domain name? It happens with a temporary test address * What happens if the computer shuts down? Site access is interrupted. With this method, you can turn your home computer into a secure server and open your PHP and Node.js projects to the world. It is the ideal solution for learning, demo and small-scale projects.