开发者社区 问答 正文

在阿里云win主机用phpnow建立了主站,怎么apache反向代理ghost博客?

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?

展开
收起
icbcman 2015-02-03 14:11:41 7088 分享
分享
版权
举报
阿里云 AI 助理回答

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.

  1. 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.

  2. 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
  1. Restart Apache: After making changes, restart Apache for the settings to take effect.
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.

有帮助
无帮助
AI 助理回答生成答案可能存在不准确,仅供参考
0 条回答
写回答
取消 提交回答