欢迎来到代码驿站!

Nginx

当前位置:首页 > 服务器 > Nginx

Nginx反向代理多域名的HTTP和HTTPS服务的实现

时间:2021-03-29 09:40:57|栏目:Nginx|点击:

当前Nginx已经反向代理了两个网站,分别是基于Windows的IIS和Linux的Apach服务器,提供网页服务。

现在有新项目的网页需要对外提供服务,需要在代理服务器上增加另外一个网站,使用HTTPS访问以及HTTP自动跳转HTTPS。由于新网页是静态页面,所以使用Docker部署在Nginx代理服务器上。相关的certificates是通过let's encrypt来获取的,都是单独的证书,没有申请通配符形式的证书。

在Nginx代理端部署SSL证书即可,后端不需要部署SSL也可以实现HTTPS访问。

Nginx代理服务器配置:

worker_processes auto;

error_log /var/log/nginx/error.log warn;
pid  /var/run/nginx.pid;

events {
 worker_connections 1024;
}

http {
 include  /usr/local/nginx/conf/mime.types;
 default_type application/octet-stream;

 log_format main '$remote_addr - $remote_user [$time_local] "$request" '
      '$status $body_bytes_sent "$http_referer" '
      '"$http_user_agent" "$http_x_forwarded_for"';

 access_log /var/log/nginx/access.log main;

 sendfile  on;
 tcp_nopush  on;
 tcp_nodelay  on;

upstream dx.exzel.co.nz {

 server 127.0.0.1:8080;
}

upstream mybusiness.exzel.co.nz {

 server 192.168.1.252:443;
}

server {
 listen 80;
 server_name dx.exzel.co.nz;
 rewrite ^(.*) https://dx.exzel.co.nz permanent;
}
server {
 listen 443;
 server_name dx.exzel.co.nz;
 ssl on;
 ssl_certificate /etc/letsencrypt/live/dx.exzel.co.nz/fullchain.pem;
 ssl_certificate_key /etc/letsencrypt/live/dx.exzel.co.nz/privkey.pem;
 ssl_session_timeout 5m;
 ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
 ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
 ssl_prefer_server_ciphers on;
 access_log /var/log/nginx/ccieerror.log ;
 location / {
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP $remote_addr;

      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_pass http://dx.exzel.co.nz;

 }
}

server {
 listen 80;
 server_name mybusiness.exzel.co.nz;
 rewrite ^(.*) https://mybusiness.exzel.co.nz permanent;
}
server {
 listen 443;
 server_name mybusiness.exzel.co.nz;
 ssl on;
 ssl_certificate /etc/letsencrypt/live/mybusiness.exzel.co.nz/fullchain.pem;
 ssl_certificate_key /etc/letsencrypt/live/mybusiness.exzel.co.nz/privkey.pem;
 ssl_session_timeout 5m;
 ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
 ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
 ssl_prefer_server_ciphers on;
 access_log /var/log/nginx/mybusiness.log ;
 location / {
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP $remote_addr;

      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_pass https://mybusiness.exzel.co.nz;

 }
}

server {
 listen 80;
 server_name www.empnz.co.nz empnz.co.nz;
  location / {
    proxy_pass http://192.168.1.15 ;
    }
 }

}

上一篇:nginx 作为反向代理实现负载均衡的例子

栏    目:Nginx

下一篇:nginx启动服务提示98: Address already in use错误的解决

本文标题:Nginx反向代理多域名的HTTP和HTTPS服务的实现

本文地址:http://www.codeinn.net/misctech/90107.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有