一个ip对应多个域名多个ssl证书配置-Nginx实现多域名证书HTTPS,Nginx使用https报错Mixed Content: The page was loaded over HTTPS, T

**第一步:**一台服务器,两个或者多个域名映射。首先购买https,获取到CA证书,两个域名就得到两套或多套证书
**第二步:**现在就是Nginx和OpenSSL的安装与配置(这里注意,一般情况下一个IP只支持一个SSL证书,那么我们现在要在一个IP上实现多个SSL证书,就必须让Nginx支持TLS SNI,由于默认的OpenSSL是没有打开TLS SNI的)

1)Nginx支持多域名SSL证书是需要OpenSSL库支持的,CentOS5.X的OpenSSL库本身不支持这种特性,需要重新下载编译,步骤如下:

wget https://www.openssl.org/source/old/1.0.2/openssl-1.0.2j.tar.gz
tar zxvf ./openssl-1.0.2j.tar.gz

2)下载Nginx,进行配置

wget http://nginx.org/download/nginx-1.8.0.tar.gz

tar zxf nginx-1.8.0.tar.gz 

cd nginx-1.8.0

./configure --prefix=/usr/local/nginx1.8.0 --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=../openssl-1.1.0e

(此处会报错:出现pcre库没找到或zlib没找到,

在CentOS下可以使用 yum -y install pcre-devel zlib-devel 进行安装缺失的组件

#再然后
 make && make install

3)检查Nginx状态

#这里-v小写的v只展示版本号,大写的-V会还会展示相关模块
/usr/local/nginx1.8.0/sbin/nginx -V

得到如下结果就说明配置好了:

nginx version: nginx/1.8.0
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-55)
built with OpenSSL 0.9.8zh 3 Dec 2015
TLS SNI support enabled      #可以看到TLS SNI support打开了
configure arguments: --prefix=/usr/local/nginx1.8.0 --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=../openssl-0.9.8zh

第三步:
配置Nginx 应用服务器,证书放置到 Nginx/conf/cert 目录下,nginx.conf文件如下:


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  www.qsafety.cn;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
		proxy_pass  http://localhost:8080;
		#Proxy Settings
      		proxy_redirect     off;
      		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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
       	    proxy_max_temp_file_size 0;
       	    proxy_connect_timeout      90;
      	 	proxy_send_timeout         90;
       	    proxy_read_timeout         90;
       	    proxy_buffer_size          4k;
       	    proxy_buffers              4 32k;
          	proxy_busy_buffers_size    64k;
        	proxy_temp_file_write_size 64k;
		}

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
	
	
	
	upstream tomcat {
		server 1x.4x.1xx.5x:8xxx;
	   }
	   
    server {
        listen    443 ssl;
        server_name  www.jobsafety.com.cn;
        ssl_certificate      ../cert/4831760_www.xxx.pem;
        ssl_certificate_key  ../cert/4830760_www.xxx.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        #ssl_protocols  SSLv2 SSLv3 TLSv1;
        ssl_protocols  SSLv2 SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

		
	location  /wwqimg {
                alias /usr/local/img/;
                index 8Sfavicon.ico;
        }


        location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto https;

        proxy_connect_timeout      240;
        proxy_send_timeout         240;
        proxy_read_timeout         240;
        proxy_pass http://tomcat;

        }
    }
	
	
	
	
	upstream localhost:8080 {
		server localhost:8080;
	   }
	   
    server {
        listen    443 ssl;
        server_name  www.xxx.cn;
        ssl_certificate      ../cert/5741842_www.xxx.cn.pem;
        ssl_certificate_key  ../cert/5741842_www.xxx.cn.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        #ssl_protocols  SSLv2 SSLv3 TLSv1;
        ssl_protocols  SSLv2 SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

		add_header  X-Frame-Options  deny;
        add_header  X-Content-Type-Options  nosniff;
        add_header  X-XSS-Protection "1; mode=block";
        add_header Strict-Transport-Security max-age=86400;
        add_header Content-Security-Policy "upgrade-insecure-requests;default-src *;script-src 'self' https://www.xxx.cn http://www.xxx.cn 'unsafe-inline' 'unsafe-eval';style-src https://www.xxx.cn http://www.xxx.cn 'self' 'unsafe-inline';frame-src 'self';connect-src 'self';img-src https://www.xxx.cn http://www.xxx.cn data: blob: 'self'";

        location / {
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header Host $http_host;
			proxy_set_header X-Forwarded-Proto https;
			proxy_connect_timeout      240;
			proxy_send_timeout         240;
			proxy_read_timeout         240;
			proxy_pass  http://localhost:8080;

        }
    }

}

底下的配置是方式http请求的静态资源访问不到

add_header Content-Security-Policy "upgrade-insecure-requests;default-src *;script-src 'self' https://www.xxx.cn http://www.xxx.cn 'unsafe-inline' 'unsafe-eval';style-src https://www.xxx.cn http://www.qsafety.cn 'self' 'unsafe-inline';frame-src 'self';connect-src 'self';img-src https://www.xxx.cn http://www.xxx.cn data: blob: 'self'";

启动Nginx:报错-

nginx: [emerg] getpwnam(“www”) failed错误

错误的原因是没有创建www这个用户,应该在服务器系统中添加www用户组和用户www,如下命令:

#/usr/sbin/groupadd -f www
#/usr/sbin/useradd -g www www

参考链接:https://blog.csdn.net/fragrant_no1/article/details/83785882
https://blog.csdn.net/fragrant_no1/article/details/83785882

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值