加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

通过suburi的单个域隔离多个nginx ssl应用程序的策略?

发布时间:2020-12-13 21:14:07 所属栏目:Nginx 来源:网络整理
导读:警告:到目前为止,我只学会了如何使用nginx为自己的域和服务器块提供应用程序.但我认为是时候深入了解一下. 为了减少对多个SSL证书或昂贵的通配符证书的需求,我想从一个nginx server_name提供多个应用程序(例如rails应用程序,php应用程序,node.js应用程序).

警告:到目前为止,我只学会了如何使用nginx为自己的域和服务器块提供应用程序.但我认为是时候深入了解一下.

为了减少对多个SSL证书或昂贵的通配符证书的需求,我想从一个nginx server_name提供多个应用程序(例如rails应用程序,php应用程序,node.js应用程序).例如rooturl / railsapp rooturl / nodejsapp rooturl / phpshop rooturl / phpblog

我不确定理想的策略.我见过或想过的一些例子:

>多个位置规则,这似乎会导致各个应用配置要求之间发生冲突,例如:不同的重写和访问要求
>后端内部端口隔离的应用程序,这可能吗?每个端口路由到自己的配置?因此配置是隔离的,可以定制到应用程序要求.
>反向代理,我不知道这是如何工作的,这是我需要研究的吗?这实际上是2吗?在线帮助似乎总是代理到其他服务器,例如apache

什么是通过子uris隔离从单个域提供的应用程序的配置要求的有效方法?

最佳答案
Nginx可以做很多事情,包括反向代理,缓存和服务内容,但是在大型环境中,各个功能被拆分以使它们更易于维护或专门使用更适合的替代方案(例如用于高容量https://的stud).

反向代理只是意味着客户端和实际应用程序之间存在的东西;它实际上是用词不当,应该被称为“服务器代理”.

要从一个域上的一个证书提供服务,请从以下内容开始:

(在Ubuntu LTS 12.04上测试过)

的/ etc / nginx的/ proxy_params

#proxy_set_header Host            $proxy_host; # instead of standard $host
proxy_set_header  X-Real-IP       $remote_addr;
proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;

在/ etc / nginx的/启用的站点 – / global_redirects

# note: must disable the built-in 
#       /etc/nginx/sites-enabled/default by removing it (it's a symlink) 
server {

    # redirects all http:// requests to https://
    # critically,passes the original host the client was trying to connect to.
    rewrite ^ https://$host$request_uri? permanent;

    # combined redirect access and error logs for easier correlation
    error_log  '/var/log/nginx/global_redirects';
    access_log '/var/log/nginx/global_redirects';

}

在/ etc / nginx的/启用的站点 – / global_ssl

# This serves all enabled-locations over ssl only.
# If there's no match,it shows the default site.

include /etc/nginx/upstreams-enabled/*; # include enabled upstream proxies

server {

    listen 443 ssl;

    ssl_certificate      /etc/nginx/server.crt;
    ssl_certificate_key  /etc/nginx/server.key;

    keepalive_timeout    70;

    root /usr/share/nginx/www;
    index index.html index.htm;

    access_log '/var/log/nginx/global_ssl';
    error_log  '/var/log/nginx/global_ssl';

    include /etc/nginx/locations-enabled/*;

}

在/ etc / nginx的/启用位置-/条

# points to hackernews but
# it could be http://10.2.4.5:401/app495 instead
location ~ ^/bar(/.*)?${

    include proxy_params;
    include apps/node;

    proxy_pass       http://news.ycombinator.com/$1;

    access_log '/var/log/nginx/bar';
    error_log  '/var/log/nginx/bar';

}

在/ etc / nginx的/启用位置-/富

location ~ ^/foo(/.*)?${

    include proxy_params;
    include apps/ruby;

    proxy_pass       http://www.linode.com/$1;

    access_log '/var/log/nginx/foo';
    error_log  '/var/log/nginx/foo';

}

/etc/nginx/upstreams-enabled/news.ycombinator.com

upstream news.ycombinator.com {
  server news.ycombinator.com;
}

/etc/nginx/upstreams-enabled/www.linode.com

upstream www.linode.com {
  server www.linode.com;
}

的/ etc / nginx的/应用/ruby

# Place ruby specific directives here

的/ etc / nginx的/应用/节点

# Place node specific directives here

请记住,这不会在页面中重写URL,因为这些是由每个应用程序生成的.相反,每个应用程序应该知道它的外部方案,主机,端口和URL基础并适当地生成链接(大多数真正的应用程序支持此).

参考文献:

> http://wiki.nginx.org/HttpProxyModule
> http://wiki.nginx.org/HttpSslModule

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读