CentOS7.5下将Node.js应用端口绑定到Web地址的配置方法
How to Reverse Proxy OS.js to https://website.com/OS.js/ on CentOS 7.5 Apache
Hey there! Let's get your OS.js app accessible via https://website.com/OS.js/ sorted out. Since you're running CentOS 7.5 with Apache, plus Webmin/Virtualmin, you've got two solid options to set up the reverse proxy—and I'll break down which is easier, plus step-by-step instructions for both.
Which is Easier: Webmin/Virtualmin or SSH?
Webmin/Virtualmin is absolutely the simpler route if you prefer a graphical interface. It cuts out the need to hunt down configuration files manually, and reduces the risk of typos breaking your Apache setup. That said, SSH is totally fine if you're comfortable with the command line and want a more direct approach.
Method 1: Using Webmin/Virtualmin (Recommended for Beginners)
- Log into your Webmin dashboard, then navigate to the Virtualmin module (if it's not visible, make sure it's enabled in Webmin's "Webmin Configuration" > "Modules").
- Select your target domain (
website.com) from the dropdown to enter its management interface. - Go to Services > Apache Webserver to access the Apache settings for this domain.
- First, ensure the required Apache modules are enabled:
- Click the Modules tab, then check the boxes for
proxyandproxy_http. - Click Save Modules to apply changes.
- Click the Modules tab, then check the boxes for
- Now add the reverse proxy rules:
- Go back to the Virtual Hosts tab, then click Edit Directives for the HTTPS version of your virtual host (labeled something like
website.com:443). - Paste these lines inside the
<VirtualHost *:443>block:ProxyPass /OS.js/ http://localhost:5000/ ProxyPassReverse /OS.js/ http://localhost:5000/ - Click Save to store the configuration.
- Go back to the Virtual Hosts tab, then click Edit Directives for the HTTPS version of your virtual host (labeled something like
- Restart Apache to apply changes:
- In the Apache Webserver interface, click Apply Changes or Restart Apache (usually found at the top of the page).
Method 2: Using SSH (For Command Line Fans)
- First, ensure the necessary Apache proxy modules are installed and enabled:
# Install modules if they aren't already present sudo yum install httpd-mod_proxy httpd-mod_proxy_http # Enable modules (CentOS uses apachectl for this) sudo apachectl enable proxy proxy_http - Locate your domain's HTTPS virtual host configuration file. Virtualmin typically stores these in:
/etc/httpd/conf.d/virtualmin/website.com-ssl.conf - Open the file with a text editor like nano:
sudo nano /etc/httpd/conf.d/virtualmin/website.com-ssl.conf - Inside the
<VirtualHost *:443>block, add the reverse proxy rules:ProxyPass /OS.js/ http://localhost:5000/ ProxyPassReverse /OS.js/ http://localhost:5000/ - Save and exit the editor (in nano, press
Ctrl+O, thenEnter, thenCtrl+X). - Test your Apache configuration to catch any syntax errors:
sudo apachectl configtest - If the test returns
Syntax OK, restart Apache to apply changes:sudo systemctl restart httpd
Key Notes to Avoid Issues
- HTTPS is crucial: Since you want to access the app via
https://website.com/OS.js/, make sure you add the proxy rules to the HTTPS virtual host configuration (not the HTTP one). - Slash consistency: The trailing slashes in
/OS.js/andhttp://localhost:5000/matter—they ensure paths are mapped correctly (e.g.,https://website.com/OS.js/loginpoints tohttp://localhost:5000/login). - Firewall cleanup: Since Apache is proxying requests internally to
localhost:5000, you don't need to keep port 5000 open to external traffic. You can close it with:sudo firewall-cmd --remove-port=5000/tcp --permanent sudo firewall-cmd --reload - OS.js binding: Double-check that your OS.js app is bound to
localhostor127.0.0.1(which it should be by default when you runnode osjs run). This ensures it's only accessible internally via Apache, not directly from the internet.
内容的提问来源于stack exchange,提问作者Steve Kess
相关产品推荐
相关产品推荐

