위 챗 애플 릿 https 와 ws, nginx 에이전트,

머리말
        최근 위 챗 애플 릿 에 관 한 웹 소켓 을 접 했 습 니 다. 애플 릿 백 엔 드 서비스 에 필요 한 https 설정 과 ws 설정 은 테스트 를 통 해 애플 릿 백 엔 드 서비스 배 치 를 실현 하 였 습 니 다.위 챗 애플 릿, SpringBoot 를 배경 으로 nginx 설정 을 사용 하여 https 설정 과 ws 설정 방안 을 해결 합 니 다.
계획
아 리 무료 CA 인증서, nginx 에이전트 전송 요청, netty 웹 소켓 서버 구축 및 심장 박동 유지
아 리 증 서 는 소개 하지 않 겠 습 니 다. 간단 합 니 다.
nginx 에이전트
애플 릿 은 https, ws (애플 릿 websocket 필요) 를 까다 롭 게 요구 합 니 다.
ws 는 사실 http 의 업그레이드 프로 토 콜 이기 때문에 하나의 포트 를 공유 할 수 있 습 니 다.
nginx 의 ngxin. 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;

	map $http_upgrade $connection_upgrade {

		default upgrade;
		'' close;
	}

	upstream websocket {
        server localhost:9999; #  websocket      
    }
	upstream web {

		server localhost:8090; #  web      
	}
    server {
        listen       443;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

		ssl on;
		ssl_certificate      214660810500.pem; #  ,     nginx.conf     
		ssl_certificate_key  214660810500.key; #  

		ssl_session_cache    shared:SSL:1m;
		ssl_session_timeout  5m;

		ssl_ciphers  HIGH:!aNULL:!MD5;
		ssl_prefer_server_ciphers  on;
		location / {
			proxy_pass http://web;
			proxy_set_header X-real-ip $remote_addr;
			proxy_set_header Host $http_host;
        }
		#   websocket  :wss://localhost/websocket
		location /websocket {
			proxy_pass http://websocket;
			proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "Upgrade";

		}
        #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;
        }

    
    }

}

웹 서비스: tomcat 8090
웹 소켓 서비스: netty 9999
메모: nginx 1.3 이상 버 전에 서 웹 소켓 의 역방향 대 리 를 지원 합 니 다.

좋은 웹페이지 즐겨찾기