Nginx使用自签证书

  baikapala

使用Openssl自签证书

cd /etc/nginx
mkdir key
cd key
# 输入密码111111
openssl genrsa -des3 -out ssl.key 1024
mv ssl.key xxx.key
openssl rsa -in xxx.key -out ssl.key
rm xxx.key
openssl req -new -key ssl.key -out ssl.csr

48fc9a1942b04b49838e67afc782ea91-image.png

sudo openssl x509 -req -days 365 -in ssl.csr -signkey ssl.key -out ssl.crt

如果需要用pfx 可以用以下命令生成

openssl pkcs12 -export -inkey ssl.key -in ssl.crt -out ssl.pfx

Nginx配置证书

user nginx;
worker_processes 3;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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;
    tcp_nodelay         on;
    keepalive_timeout   10m;
    types_hash_max_size 2048;
    client_max_body_size 2048m;
    
    include            /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

	 #同时开启http
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        
       location /dtmp {
            proxy_pass   http://127.0.0.1:8080;
        }

        location /atp {
            proxy_pass   http://127.0.0.1:8081/atp;
        }
       
        location /rmp {
            proxy_pass   http://127.0.0.1:8081/rmp;
        }

       location /pts {
            proxy_pass   http://127.0.0.1:8081/pts;
        }
       
      location / {
          root /home/local/dtmp/web;
          index index.html index.htm;
       }

    }
    
	 #http转https
    #server {
    #    listen       80;
    #    server_name  192.168.53.117;
    #    rewrite ^(.*)$ https://$host$1 permanent;
    #}

    server {
        listen       443 ssl;
        server_name  192.168.53.117;

        ssl_certificate      /etc/nginx/key/ssl.crt;
        ssl_certificate_key  /etc/nginx/key/ssl.key;

        ssl_session_timeout 5m;
        ssl_protocols SSLv2 SSLv3 TLSv1;
        ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
        ssl_prefer_server_ciphers on;

        location /dtmp {
            proxy_pass   http://127.0.0.1:8080;
        }

        location /atp {
            proxy_pass   http://127.0.0.1:8081/atp;
        }
       
        location /rmp {
            proxy_pass   http://127.0.0.1:8081/rmp;
        }

       location /pts {
            proxy_pass   http://127.0.0.1:8081/pts;
        }
       
      location / {
          root /home/local/dtmp/web;
          index index.html index.htm;
       }
    }

   #静态资源,没有走https,也可以单独配置
   server {
        listen       8099;
        server_name  localhost;

        location / {
            root   /home/local/dtmp/resource;
            index  index.html index.htm;
        }
    }

}

以前,我总以为自己是菜鸟,也总想着早起的鸟儿有虫吃。直到有一天我想飞,才愕然的发现自己没有翅膀和羽毛,我竟然是菜虫!早起的虫儿被鸟吃……原来,百足应该厚积薄发!