Nginx 配置 HTTPS 服务器

Nginx 配置 HTTPS 并不复杂,主要有两个步骤:签署第三方可信任的 SSL 证书 和 配置 HTTPS

我的证书是在腾讯云上申请的地址 cer

nginx.conf 配置内容


user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


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

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;
	
   upstream move{
        server 127.0.0.1:9120;
   }


   server {
        listen       80;
        listen       443 ssl;
	ssl_certificate   certificate_bundle.crt;
	ssl_certificate_key  certificate.key;

	client_max_body_size 20M;
    client_body_buffer_size 1M;
    #charset koi8-r;

    #access_log  logs/host.access.log  main;
        

	location /(css|js|fonts|img)/ {
        	access_log off;
        	expires 1d;
       	 	root "/root/vue-admin/dist";
        	try_files $uri @backend;
	}

	location / {
        	try_files /_not_exists_ @backend;
	}

	location @backend {
        	proxy_set_header X-Forwarded-For $remote_addr;
       	 	proxy_set_header Host            $http_host;
        	proxy_pass http://127.0.0.1:9801;
    	}	

	location /im/ {
    		client_max_body_size 20M;
   		proxy_pass http://127.0.0.1:9002;
	}

  }
 

    include /etc/nginx/conf.d/*.conf;
}