My Website is www.cngirls.net on the PHPnow.
Now I made a blogwww.cngirls.net/blog on Node.js,so I want to use apache proxy.
Can you tell me how to use apache proxy can make :2368 disappear?
Think about css and js on the html,do <base> must be use?
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
To configure Apache as a reverse proxy to hide the port number (in your case, :2368) for your Node.js application running on www.cngirls.net/blog, you can follow these steps. This will ensure that visitors access your blog without seeing the port in the URL and also correctly handle CSS, JS, and other assets.
Edit Your Apache Configuration File: You'll need to edit the main Apache configuration file, typically located at /etc/apache2/sites-available/000-default.conf
on Ubuntu or /etc/httpd/conf/httpd.conf
on CentOS/RHEL. If you have a custom virtual host configuration for your domain, edit that file instead.
Set Up a Reverse Proxy: Within the VirtualHost block for your domain (www.cngirls.net
), add the following lines to set up the reverse proxy:
<VirtualHost *:80>
ServerName www.cngirls.net
DocumentRoot /path/to/your/phpnow/public_html
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# Reverse Proxy configuration for your Node.js app
ProxyPass /blog http://localhost:2368
ProxyPassReverse /blog http://localhost:2368
# Ensure that Apache serves correct content types for static assets
<Location /blog>
ProxyPassReverseCookiePath / /
ProxyHTMLExtended On
ProxyHTMLEnable On
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|http://localhost:2368|/blog|niq"
</Location>
# Other Apache configurations go here...
</VirtualHost>
ProxyPass /blog http://localhost:2368
forwards requests from /blog
to your Node.js app running on port 2368.ProxyPassReverse /blog http://localhost:2368
ensures that any redirects issued by the Node.js app are correctly rewritten back to /blog
.The <Location>
block includes additional directives to handle HTML content substitution, which is useful if your Node.js app generates links with the full URL including the port. The Substitute
directive replaces occurrences of http://localhost:2368
with /blog
in the HTML responses to maintain proper URLs for resources like CSS and JS files.
Enable Required Modules: Depending on your Apache setup, you might need to enable the proxy
, proxy_http
, and substitute
modules. You can do this with commands like:
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod substitute
sudo systemctl restart apache2 # For systems using systemd
# or
sudo service apache2 restart # For older systems
With these configurations in place, visitors accessing www.cngirls.net/blog
should not see the port :2368 in their browser's address bar, and your CSS, JS, and other assets should load correctly without needing to adjust paths in your HTML code.