重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

nginx配置https自签名(openssl生成)证书-创新互联

openssl生成证书

  1. openssl genrsa -out server.key 2048
  2. openssl req -new -key server.key -out server.csr
  3. openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
[nginx@machine certificate]$  openssl genrsa -out server.key 2048
Generating RSA private key, 2048 bit long modulus
..+++
......................................................................+++
e is 65537 (0x10001)
[nginx@machine certificate]$ ll
total 4
-rw-r----- 1 nginx nginx 1679 Jul 11 16:35 server.key
[nginx@machine certificate]$ 
[nginx@machine certificate]$ openssl req -new -key server.key -out server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,

If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:cn
State or Province Name (full name) []:gd
Locality Name (eg, city) [Default City]:gz
Organization Name (eg, company) [Default Company Ltd]:ai
Organizational Unit Name (eg, section) []:ai
Common Name (eg, your name or your server's hostname) []:
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[nginx@machine certificate]$ 
[nginx@machine certificate]$ openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
Signature ok
subject=/C=cn/ST=gd/L=gz/O=ai/OU=ai
Getting Private key
[nginx@machine certificate]$ ll
total 12
-rw-r----- 1 nginx nginx 1099 Jul 11 16:36 server.crt
-rw-r----- 1 nginx nginx  952 Jul 11 16:35 server.csr
-rw-r----- 1 nginx nginx 1679 Jul 11 16:35 server.key
[nginx@machine certificate]$ 

nginx配置

[nginx@machine ~]$ cd /etc/nginx/
[nginx@machine nginx]$ more 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 zuul_nginx {
    server 10.13.22.104:8080;
    server 10.13.22.105:8080;
    server 10.13.22.106:8080;
    server 10.13.22.107:8080;
}

server {
    listen 18010 ssl;
    #listen 443 ssl;
    #server_name 10.13.22.124;
    ssl on;
    ssl_certificate /app/nginx/certificate/server.crt;
    ssl_certificate_key /app/nginx/certificate/server.key;
    ssl_session_timeout  5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    #ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers   on;
    location /ouyidaorder {
        proxy_pass http://zuul_nginx;
    }
}

server {
    listen 8080 ssl;
    ssl on;
    ssl_certificate /app/nginx/certificate/server.crt;
    ssl_certificate_key /app/nginx/certificate/server.key;
    ssl_session_timeout  5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers   on;
    location /ouyidaorder {
        proxy_pass http://zuul_nginx;
    }
}

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

}

用root重启nginx。

测试

(1)浏览器访问:https://10.13.22.124:8080/ouyidaorder/api/Subscribe
(2)curl https://10.13.22.124:18010/ouyidaorder/api/Subscribe

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


新闻名称:nginx配置https自签名(openssl生成)证书-创新互联
文章URL:http://cqcxhl.cn/article/iijee.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP