如何使用apache将不同的子域路由到不同的端口/服务器?

发布于 2025-01-02 12:27:26 字数 1392 浏览 2 评论 0原文

在我的开发机器上,我希望能够拥有一个 SSL 服务器和一个非 SSL 服务器(两者都运行相同的代码......但运行这两个服务器是最容易的部分。)

对于我的常规服务器:我想要它为 sub1.mydomain.com

所以,我修改了我的 VirtualHost,这样,我不再说

mydomain.com
*.mydomain.com,

然后

sub1.mydomain.com
*.sub1.mydomain.com

是 SSL 服务器,而是说

sub2.mydomain.com
*.sub2.mydomain.com

除了,每当我到达 sub2.mydomain url 时,附加到 sub1 进程的服务器的请求。

我在这里做错了什么?

我在 Rails 和 apache 上使用 ruby​​。

编辑:添加实际的虚拟主机

<VirtualHost *:80>
    DocumentRoot "/Users/me/projects/myproject/public"
    ServerName reg.mydomain.com
    #ServerAlias *.reg.mydomain.com
    ProxyPass / http://localhost:3001/
    ProxyPassReverse / http://localhost:3001
</VirtualHost>


<VirtualHost *:443>
    SSLEngine on
    SSLProxyEngine On
    RequestHeader set Front-End-Https "On"
    CacheDisable *
    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
    DocumentRoot "/Users/me/projects/myproject/public"
    ServerName ssl.mydomain.com
    #ServerAlias *.ssl.mydomain.com
    SSLCertificateKeyFile "/private/etc/apache2/certs/server.key"
    SSLCertificateFile "/private/etc/apache2/certs/server.crt"

    ProxyPass / https://localhost:3002/
    ProxyPassReverse / https://localhost:3002
    ProxyPreserveHost on    
</VirtualHost>

On my dev machine, I want to be able to have an SSL server, and a non-SSL server (both running off the same code... but running both servers is the easy part.)

For my regular server: I want it to be sub1.mydomain.com

so, I've modified my VirtualHost such that instead of saying

mydomain.com
*.mydomain.com,

it says

sub1.mydomain.com
*.sub1.mydomain.com

and then for the SSL server, I just said

sub2.mydomain.com
*.sub2.mydomain.com

except, whenever I got to a sub2.mydomain url, the server attached to sub1 processes the request.

What am I doing wrong here?

I'm using ruby on rails, and apache.

EDIT: added the actual virtual hosts

<VirtualHost *:80>
    DocumentRoot "/Users/me/projects/myproject/public"
    ServerName reg.mydomain.com
    #ServerAlias *.reg.mydomain.com
    ProxyPass / http://localhost:3001/
    ProxyPassReverse / http://localhost:3001
</VirtualHost>


<VirtualHost *:443>
    SSLEngine on
    SSLProxyEngine On
    RequestHeader set Front-End-Https "On"
    CacheDisable *
    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
    DocumentRoot "/Users/me/projects/myproject/public"
    ServerName ssl.mydomain.com
    #ServerAlias *.ssl.mydomain.com
    SSLCertificateKeyFile "/private/etc/apache2/certs/server.key"
    SSLCertificateFile "/private/etc/apache2/certs/server.crt"

    ProxyPass / https://localhost:3002/
    ProxyPassReverse / https://localhost:3002
    ProxyPreserveHost on    
</VirtualHost>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦情居士 2025-01-09 12:27:26

听起来您正在尝试做命名虚拟主机?

http://httpd.apache.org/docs/2.2/vhosts/name -based.html

假设rails没有做任何太时髦的事情,你可以尝试拥有一个如下所示的虚拟主机:

NameVirtualHost *

<VirtualHost *>
ServerName sub1.mydomain.com
DocumentRoot /var/www/sub1 or point this to the server instead.
</VirtualHost>

<VirtualHost *>
ServerName sub2.mydomain.com
DocumentRoot /var/www/sub2 or point this to the server instead.
</VirtualHost>

It sounds like you're trying to do named virtual hosts?

http://httpd.apache.org/docs/2.2/vhosts/name-based.html

Assuming that rails isn't doing anything too funky, you can try having a virtual host that looks like this:

NameVirtualHost *

<VirtualHost *>
ServerName sub1.mydomain.com
DocumentRoot /var/www/sub1 or point this to the server instead.
</VirtualHost>

<VirtualHost *>
ServerName sub2.mydomain.com
DocumentRoot /var/www/sub2 or point this to the server instead.
</VirtualHost>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文