>  기사  >  운영 및 유지보수  >  Nginx에서 https를 업그레이드하는 방법

Nginx에서 https를 업그레이드하는 방법

WBOY
WBOY앞으로
2023-05-14 16:49:12946검색

인증서 다운로드

인증서 콘솔에서 nginx 버전 인증서를 다운로드하세요. 압축 해제 후 로컬 영역에 다운로드되는 압축 파일 패키지에는 다음이 포함됩니다.

  • .pem 파일: 인증서 파일

  • .key 파일: 인증서의 개인 키 파일(신청 시 csr 자동 생성을 선택하지 않은 경우) 인증서의 경우 해당 파일이 없습니다)

nginx 구성

1. nginx 설치 디렉터리에 cert 디렉터리를 생성하고 csr을 생성한 경우 다운로드한 모든 파일을 해당 디렉터리에 복사합니다. 인증서를 신청할 때 파일을 직접 추가하세요. 개인 키 파일은 인증서 디렉터리에 있습니다.

2. nginx 설치 디렉토리

#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;  #开启gzip
  gzip_min_length 1k; #低于1kb的资源不压缩
  gzip_comp_level 3; #压缩级别【1-9】,越大压缩率越高,同时消耗cpu资源也越多,建议设置在4左右。
  gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css; #需要压缩哪些响应类型的资源,多个空格隔开。不建议压缩图片,下面会讲为什么。
  gzip_disable "msie [1-6]\."; #配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持)
  gzip_vary on; #是否添加“vary: accept-encoding”响应头

  server {
    listen    80 default backlog=2048; #配置http可用
    listen    443 ssl; #配置https
    server_name localhost;

    ssl_certificate   ../cert/hzzly.pem; #配置证书文件
    ssl_certificate_key ../cert/hzzly.key; #配置私钥文件

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

    ssl_ciphers high:!anull:!md5;
    ssl_prefer_server_ciphers on;

    location / {
      root  /home/hzzly;
      index index.html index.htm;
    }

    # location ^~ /apis/ {
    #   proxy_set_header host $host;
    #   proxy_set_header x-real-ip $remote_addr;
    #   proxy_set_header x-forwarded-server $host;
    #   # 匹配任何以 /apis/ 开始的请求,并停止匹配 其它location
    #   proxy_pass http://xxxxxxxxxx/;
    # }

    # location ^~ /assets/ {
    #   gzip_static on;
    #   expires max;
    #   add_header cache-control public;
    # }
  }
}

아래의 conf 디렉토리에서 nginx.conf 파일을 엽니다. nginx를 다시 시작하세요

$ cd /usr/local/nginx/sbin
$ ./nginx -s reload

자세한 오류 설명

1. nginx가 SSL 모듈을 활성화하지 않으면 오류가 발생합니다. https

nginx를 구성할 때 메시지가 표시됩니다. [emerg] "ssl" 매개변수에 ngx_http_ssl_module이 필요합니다...

nginx는 SSL 모듈을 켭니다

소스 패키지로 전환합니다.

$ cd /usr/local/src/nginx-1.16.0

수정 새로운 구성 매개변수

$ ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

구성이 완료되면 Command를 실행하세요

$ make //这里不要进行make install,否则就是覆盖安装

원래 설치된 nginx를 백업하세요

$ cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

새로 컴파일된 nginx가 원본 nginx를 덮어씁니다

$ cp ./objs/nginx /usr/local/nginx/sbin/

nginx를 다시 시작하세요

$ cd /usr/local/nginx/sbin
$ ./nginx -s reload

위 내용은 Nginx에서 https를 업그레이드하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 yisu.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제