记录Docker+Nginx搭建多域名访问Https配置

记录一次在公司线上环境使用nginx进行多域名反向代理的配置

user root;
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    underscores_in_headers on; 
    resolver 8.8.8.8; 
    server {
        listen       80;
        server_name  www.v9chn.com;
        rewrite ^(.*)$ https://$host$1 permanent;
    }
    server {
        listen       80;
        server_name  xs.v9chn.com;
        rewrite ^(.*)$ https://$host$1 permanent;
    }
    server {
        listen 443 ssl;
        server_name  www.v9chn.com;
        root html;
        index index.html index.htm;
        ssl_certificate cert/3706543_www.v9chn.com.pem;  # 将domain name.pem替换成您证书的文件名。
        ssl_certificate_key cert/3706543_www.v9chn.com.key;   #将domain name.key替换成您证书的密钥文件名。
        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;
        location / {
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header Host $http_host;
              proxy_pass http://192.168.18.80:90;
        }
    }
    server {
        listen 443 ssl;
        server_name xs.v9chn.com;
        root html;
        index index.html index.htm;
        ssl_certificate cert/3813423_xs.v9chn.com.pem;
                                                                                                                        1,10         顶端
  • 使用underscores_in_headers on; 配置处理nginx请求头带下划线丢失问题
  • 使用resolver 8.8.8.8; 解决 no resolver defined to resolve xs.v9chn.com, client: 115.236.167.10
  • 使用不同的域名同时监听80端口并反向代理到其他不同的地址
  • 配置ssl模块进行Https配置

docker-compose.yml文件配置信息

version: '3.1'
services:
  nginx:
    image: nginx
    container_name: nginx
    restart: always
    environment:
      TZ: Asia/Shanghai
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./data:/usr/share/nginx/html
      - ./conf/nginx.conf:/etc/nginx/nginx.conf
      - ./conf/cert/:/etc/nginx/cert/
      - ./logs:/var/log/nginx/

你可能感兴趣的:(记录Docker+Nginx搭建多域名访问Https配置)