windows 아래 nginx 에서 OpenSSL 자체 서명 인증 서 를 설정 합 니 다.

5515 단어 nginx
판본
nginx:1.16.1
git 설치
windos 에서 git 도 구 를 설치 한 후 openssl 도 구 를 가 져 갈 수 있 습 니 다.
인증서 생 성 신청 파일 과 비밀 키 파일
openssl  req -nodes -newkey rsa:1024 -out myreq.pem -keyout privatekey.pem
# req:request   ,               
# -nodes:   pin ,    
# -newkey:               ,     2048
# -out:        ,     
# -keyout:    

인증서 생 성
신청 파일 과 비밀 키 를 사용 하여 인증 서 를 신청 하고 자신 에 게 인증 서 를 발급 합 니 다.
openssl req -in myreq.pem -x509 -key privatekey.pem -out mycert.pem -days 365
# -in:            
# -x509:    
# -key:    
# -out:       
# -days:     

설정 nginx
위 에서 생 성 된 파일 을 nginx/conf/cert 디 렉 터 리 에 놓 고 디 렉 터 리 구조:
└─conf
    │  nginx.conf
    └─cert
            mycert.pem
            myreq.pem
            privatekey.pem
              openssl    https.sh

전체 nginx 프로필 은 다음 과 같 습 니 다:
#user  nobody;
worker_processes  1;

#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;
    
    #         
	upstream backend_server{
		# 1
		server 127.0.0.1:8080 weight=1 max_fails=2 fail_timeout=5s;
		keepalive 100;
	}
    
    server {
        listen       80;
        server_name  192.168.1.2;

        #  http       https
        rewrite ^(.*)$ https://$host$1 permanent; 
        #rewrite ^/(.*) https://$server_name$request_uri redirect;
		
        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        
        location / {
            root   html;
            index  index.html index.htm;
        }

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

    # HTTPS server
    #
    server {
        listen       443 ssl;
        server_name  192.168.1.2;
        keepalive_timeout  70;
        
        ssl_certificate      cert/mycert.pem;
        ssl_certificate_key  cert/privatekey.pem;

        ssl_session_cache    shared:SSL:10m;
        ssl_session_timeout  10m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
       
        #         
        location = / {
           rewrite ^(.*)$ http://$host/server/ redirect; 
            #root   html;
            #index  index.html index.htm;
        }
		#        
		location /server/{
            proxy_connect_timeout 5s;
            proxy_http_version 1.1;
            proxy_set_header Connection "";
            
			proxy_pass http://backend_server;            
		}
       
        
        location /status{
            stub_status on;
        }
    }
	# include vhost/*.conf;

}

좋은 웹페이지 즐겨찾기