You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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.


  1. 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").
  2. Select your target domain (website.com) from the dropdown to enter its management interface.
  3. Go to Services > Apache Webserver to access the Apache settings for this domain.
  4. First, ensure the required Apache modules are enabled:
    • Click the Modules tab, then check the boxes for proxy and proxy_http.
    • Click Save Modules to apply changes.
  5. 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.
  6. 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)

  1. 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
    
  2. Locate your domain's HTTPS virtual host configuration file. Virtualmin typically stores these in:
    /etc/httpd/conf.d/virtualmin/website.com-ssl.conf
    
  3. Open the file with a text editor like nano:
    sudo nano /etc/httpd/conf.d/virtualmin/website.com-ssl.conf
    
  4. Inside the <VirtualHost *:443> block, add the reverse proxy rules:
    ProxyPass /OS.js/ http://localhost:5000/
    ProxyPassReverse /OS.js/ http://localhost:5000/
    
  5. Save and exit the editor (in nano, press Ctrl+O, then Enter, then Ctrl+X).
  6. Test your Apache configuration to catch any syntax errors:
    sudo apachectl configtest
    
  7. 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/ and http://localhost:5000/ matter—they ensure paths are mapped correctly (e.g., https://website.com/OS.js/login points to http://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 localhost or 127.0.0.1 (which it should be by default when you run node osjs run). This ensures it's only accessible internally via Apache, not directly from the internet.

内容的提问来源于stack exchange,提问作者Steve Kess

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:17:17