简体   繁体   English

将流量重定向到具有端口号的域,而不在URL中显示端口号

[英]Redirect traffic to a domain with a port number without showing the port number in the URL

I have Node.js/Angularjs/Gulp application running on www.myurl.com:3001 and I would like to have a "clean" URL www.myurl.com. 我在www.myurl.com:3001上运行了Node.js / Angularjs / Gulp应用程序,我希望有一个“干净的” URL www.myurl.com。 So I would like to redirect the traffic from www.myurl.com to www.myurl.com:3001, which is pretty straight foreward with a .htaccess mod rewrite condition. 因此,我想将流量从www.myurl.com重定向到www.myurl.com:3001,使用.htaccess mod重写条件,这是非常直接的。 But what I get is now a redirect from www.myurl.com to www.myurl.com:3001 and I would like to see the application running on port 3001 under the URL without any additional port, so that any user that visits the URL www.myurl.com sees the application running on www.myurl.com:3001, but has a "clean" URL without any port number in his browser:www.myurl.com. 但是我现在得到的是从www.myurl.com到www.myurl.com:3001的重定向,我希望看到该应用程序在URL下的端口3001上运行,而没有任何其他端口,以便任何访问该URL的用户www.myurl.com看到该应用程序在www.myurl.com:3001上运行,但是在其浏览器:www.myurl.com中具有“干净” URL,但没有任何端口号。

What would be the best way to do it? 最好的方法是什么? Here´s what I got so far: 这是到目前为止我得到的:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.myurl.com [NC]
RewriteRule (.*) http://www.myurl.com:3001/$1 [R=301,L]

Any hints or help would be appreciated, thanks! 任何提示或帮助,将不胜感激,谢谢!

You can't just redirect it, as that will always show the port. 您不能只重定向它,因为它将始终显示端口。

You need to configure a reverse proxy in Apache. 您需要在Apache中配置反向代理。 This can be done like in this StackOverflow answer and would look a little like this in your apache configuration: 这可以像在StackOverflow答案中那样完成,在您的apache配置中看起来像这样:

<VirtualHost *:80>
    ServerAdmin admin@myurl.com
    ServerName myurl.com
    ServerAlias www.myurl.com

    ProxyRequests off

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    <Location />
        ProxyPass http://localhost:3001/
        ProxyPassReverse http://localhost:3001/
    </Location>
</VirtualHost>

Two methods 两种方法

  1. change port number 更改端口号

    Listen 3001

http://httpd.apache.org/docs/2.2/mod/mpm_common.html#listen http://httpd.apache.org/docs/2.2/mod/mpm_common.html#listen

  1. Reverse proxy 反向代理

    <VirtualHost *:80> ProxyPreserveHost On ProxyRequests Off ServerName www.myurl.com ServerAlias myurl.com ProxyPass / http://myurl.com:3001/ ProxyPassReverse / http://myurl.com:3001/ </VirtualHost>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM