如何在Ubuntu 18.04上部署Hyperledger Fabric Composer REST API公网访问
Hey there! Let's walk through getting your Hyperledger Fabric app accessible to other users on your local network step by step—no need to stress if you’re new to Apache or Ubuntu, we’ll break everything down simply.
Step 1: Make your app listen to all network interfaces
Right now, your app is probably only bound to localhost (127.0.0.1), which means it can only be accessed from your Ubuntu machine itself. We need to change that so it listens to all available network interfaces:
- Locate your app’s startup configuration (if it’s a Node.js app, for example, look for a line like
app.listen(8080, '127.0.0.1')). - Modify it to listen on
0.0.0.0instead:app.listen(8080, '0.0.0.0'). - Restart your app, then test locally with
curl http://<your-ubuntu-machine-ip>:8080to confirm it’s reachable via your machine’s actual IP.
Step 2: Open the port in Ubuntu’s firewall
Ubuntu 18.04 uses ufw by default, so we need to allow incoming traffic on port 8080:
- Run this command to open the port:
sudo ufw allow 8080/tcp - Verify the rule is active with:
You should see a line allowingsudo ufw status8080/tcpin the output.
Step 3: Test access from another local machine
Grab another device on your LAN, open a browser, and enter http://<your-ubuntu-machine-lan-ip>:8080. If it loads your app, you’re already halfway there!
- If it doesn’t work:
- Double-check your Ubuntu machine’s LAN IP (run
ip addr showand look for theinetentry under your main network interface, likeenp0s3). - Confirm your app is really listening on
0.0.0.0withnetstat -tulpn | grep 8080—the output should show0.0.0.0:8080, not127.0.0.1:8080.
- Double-check your Ubuntu machine’s LAN IP (run
Step 4: Use Apache as a reverse proxy (optional, for port 80 or custom domains)
If you want users to access your app without typing a port number, or use a custom local domain, Apache reverse proxy is the way to go. Here’s how to set it up:
- Install Apache first:
sudo apt update sudo apt install apache2 - Enable the required Apache modules for proxying:
sudo a2enmod proxy proxy_http proxy_balancer lbmethod_byrequests - Create a virtual host configuration file:
Paste this content, replacing placeholders with your details:sudo nano /etc/apache2/sites-available/fabric-app.conf<VirtualHost *:80> ServerName fabric-app.local # Optional: use a custom local domain ServerAdmin your-email@example.com # Forward traffic to your app's local port ProxyPreserveHost On ProxyPass / http://127.0.0.1:8080/ ProxyPassReverse / http://127.0.0.1:8080/ # Log settings ErrorLog ${APACHE_LOG_DIR}/fabric-app-error.log CustomLog ${APACHE_LOG_DIR}/fabric-app-access.log combined </VirtualHost> - Enable the virtual host and restart Apache:
sudo a2ensite fabric-app.conf sudo systemctl restart apache2 - Open port 80 in the firewall (if not already open):
sudo ufw allow 80/tcp - Now users can access your app via
http://<your-ubuntu-machine-ip>orhttp://fabric-app.local(if you set up local DNS for the custom domain).
Quick Troubleshooting Tips
- If Apache proxy isn’t working: Check the error log at
/var/log/apache2/fabric-app-error.logfor configuration or permission issues. - If LAN access still fails: Make sure your router isn’t blocking traffic to your Ubuntu machine, and that Hyperledger Fabric’s core services are running properly.
内容的提问来源于stack exchange,提问作者Khaksar

