Linux SSL证书安装

计算机软件开发 2024-9-19 04:22:31 74 0 来自 中国
1. 查找nginx 的安装位置:

root@VERDE-SICC-APPLICATION1:/# find / -name 'nginx'/home/apache/blueview-tomcat/webapps/ROOT/static/vendor/editormd/lib/codemirror/mode/nginx/etc/default/nginx/etc/nginx/etc/logrotate.d/nginx/etc/init.d/nginx/etc/ufw/applications.d/nginx/var/lib/nginx/var/log/nginx/usr/lib/nginx/usr/sbin/nginx/usr/share/nginx/usr/share/doc/nginxroot@VERDE-SICC-APPLICATION1:/# find / -name 'nginx.conf'/etc/nginx/nginx.conf2. 上传证书:

root@VERDE-SICC-APPLICATION1:/etc/nginx# lsconf.d        fastcgi_params  koi-win     modules-available  nginx.conf    scgi_params      sites-enabled  uwsgi_paramsfastcgi.conf  koi-utf         mime.types  modules-enabled    proxy_params  sites-available  snippets       win-utfroot@VERDE-SICC-APPLICATION1:/etc/nginx# mkdir certroot@VERDE-SICC-APPLICATION1:/etc/nginx# rz ZMODEM  Session started            e50------------------------             Sent  8444101_cloud.hnverde.com_nginx.zip               root@VERDE-SICC-APPLICATION1:/etc/nginx# ls8444101_cloud.hnverde.com_nginx.zip  conf.d        fastcgi_params  koi-win     modules-available  nginx.conf    scgi_params      sites-enabled  uwsgi_paramscert                                 fastcgi.conf  koi-utf         mime.types  modules-enabled    proxy_params  sites-available  snippets       win-utfroot@VERDE-SICC-APPLICATION1:/etc/nginx# 3. 移动证书到 cert 文件夹

root@VERDE-SICC-APPLICATION1:/etc/nginx# mv 8444101_cloud.hnverde.com_nginx.zip certroot@VERDE-SICC-APPLICATION1:/etc/nginx# lscert    fastcgi.conf    koi-utf  mime.types         modules-enabled  proxy_params  sites-available  snippets      win-utfconf.d  fastcgi_params  koi-win  modules-available  nginx.conf       scgi_params   sites-enabled    uwsgi_paramsroot@VERDE-SICC-APPLICATION1:/etc/nginx# cd certroot@VERDE-SICC-APPLICATION1:/etc/nginx/cert# ls8444101_cloud.hnverde.com_nginx.ziproot@VERDE-SICC-APPLICATION1:/etc/nginx/cert# unzip 8444101_cloud.hnverde.com_nginx.zip Archive:  8444101_cloud.hnverde.com_nginx.zipAliyun Certificate Download  inflating: 8444101_cloud.hnverde.com.pem    inflating: 8444101_cloud.hnverde.com.key  root@VERDE-SICC-APPLICATION1:/etc/nginx/cert# ls8444101_cloud.hnverde.com.key  8444101_cloud.hnverde.com_nginx.zip  8444101_cloud.hnverde.com.pem4. 设置

server{        listen 443 ssl;        server_name cloud.hnverde.com;        root /usr/share/nginx/html;        index index.html index.htm;        ssl_certificate cert/8444101_cloud.hnverde.com.pem;        ssl_certificate_key cert/8444101_cloud.hnverde.com.key;        ssl_session_timeout  5m;        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;        ssl_prefer_server_ciphers on;        location / {                 root /usr/share/nginx/html;                 proxy_pass http://cloud.hnverde.com;                 index index.html index.htm;       }       location ~ .*.(jpg|jpeg|gif|png|swf|rar|zip|css|js)$ {                 proxy_pass http://cloud.hnverde.com;       }}5. 完备nginx.conf 设置

user www-data;worker_processes auto;pid /run/nginx.pid;#include /etc/nginx/modules-enabled/*.conf;events {        worker_connections 768;        # multi_accept on;}http{server{                listen 80;                server_name  cloud.hnverde.com;                location / {                        root /usr/share/nginx/html;                        try_files $uri $uri/ @router;                        index index.html;                }        location @router {            rewrite ^.*$ https://$host$1;        }        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }                ##        # Basic Settings        ##        sendfile off;        tcp_nopush on;        tcp_nodelay on;        keepalive_timeout 65;        types_hash_max_size 2048;        # server_tokens off;        # server_names_hash_bucket_size 64;        # server_name_in_redirect off;        include /etc/nginx/mime.types;        default_type application/octet-stream;        ##        # SSL Settings        ##            listen 443 ssl;        server_name cloud.hnverde.com;        root /usr/share/nginx/html;        index index.html index.htm;        ssl_certificate cert/8444101_cloud.hnverde.com.pem;        ssl_certificate_key cert/8444101_cloud.hnverde.com.key;        ssl_session_timeout  5m;        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;        ssl_prefer_server_ciphers on;        ##        # Logging Settings        ##        access_log /var/log/nginx/access.log;        error_log /var/log/nginx/error.log;        ##        # Gzip Settings        ##        gzip on;        # gzip_vary on;        # gzip_proxied any;        # gzip_comp_level 6;        # gzip_buffers 16 8k;        # gzip_http_version 1.1;        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;        ##        # Virtual Host Configs        ##        #include /etc/nginx/conf.d/*.conf;        #include /etc/nginx/sites-enabled/*;}}#mail {#       # See sample authentication script at:#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript# #       # auth_http localhost/auth.php;#       # pop3_capabilities "TOP" "USER";#       # imap_capabilities "IMAP4rev1" "UIDPLUS";# #       server {#               listen     localhost:110;#               protocol   pop3;#               proxy      on;#       }# #       server {#               listen     localhost:143;#               protocol   imap;#               proxy      on;#       }#}6. 前端可以了,但是背景还不是https 的,以是表现跨域问题

#  重新加载设置nginx -s reload7. 背景以转发方式完成,设置如下

nginx.conf 设置
user www-data;worker_processes auto;pid /run/nginx.pid;#include /etc/nginx/modules-enabled/*.conf;events {        worker_connections 768;        # multi_accept on;}http{#server{#                listen 80;#                server_name  cloud.****.com;               #                location / {#                        root /usr/share/nginx/html;#                        try_files $uri $uri/ @router; #                       index index.html;#                }#}server {    listen 80;    #请填写绑定证书的域名    server_name cloud.***.com;     #把http的域名哀求转成https    return 301 https://$host$request_uri; }        ##        # Basic Settings        ##        sendfile off;        tcp_nopush on;        tcp_nodelay on;        keepalive_timeout 65;        types_hash_max_size 2048;        # server_tokens off;        # server_names_hash_bucket_size 64;        # server_name_in_redirect off;        include /etc/nginx/mime.types;        default_type application/octet-stream;server{        ##        # SSL Settings        ##        listen 443 ssl;        server_name cloud.hnverde.com;        root /usr/share/nginx/html;        index index.html index.htm;        ssl_certificate cert/8444101_cloud.***.com.pem;        ssl_certificate_key cert/8444101_cloud.****.com.key;        ssl_session_timeout  5m;        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;        ssl_prefer_server_ciphers on;        location / {        #网站主页路径。此路径仅供参考,具体请您按照现实目次利用。         #比方,您的网站主页在 Nginx 服务器的 /etc/www 目次下,则请修改 root 反面的 html 为 /etc/www。        root /usr/share/nginx/html;        index index.html index.htm;    }         location /api {                           #后端接口设置           proxy_pass http://120.77.**.**:6557/api; #本机的9999后端api接口,留意这个端口是要和yaml文件的端口一致           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;       }        ##        # Logging Settings        ##        access_log /var/log/nginx/access.log;        error_log /var/log/nginx/error.log;        ##        # Gzip Settings        ##        gzip on;        # gzip_vary on;        # gzip_proxied any;        # gzip_comp_level 6;        # gzip_buffers 16 8k;        # gzip_http_version 1.1;        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;        ##        # Virtual Host Configs        ##        #include /etc/nginx/conf.d/*.conf;        #include /etc/nginx/sites-enabled/*;}}#mail {#       # See sample authentication script at:#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript# #       # auth_http localhost/auth.php;#       # pop3_capabilities "TOP" "USER";#       # imap_capabilities "IMAP4rev1" "UIDPLUS";# #       server {#               listen     localhost:110;#               protocol   pop3;#               proxy      on;#       }# #       server {#               listen     localhost:143;#               protocol   imap;#               proxy      on;#       }#}8. 访问所在:

https://120...195:443/api/Login/GetCode
3.png 9.  同理,server.js 内里设置也要变:

4.png 10. 增补,项目图片放在Data目次下,以是要在 nginx.conf  参加

  location /Data {                           #获取后端图片           proxy_pass http://120.77.144.195:6557/Data; #本机的9999后端api接口,留意这个端口是要和yaml文件的端口一致           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;       }// 同理        location /Log {                           #后端接口设置           proxy_pass http://120.77.144.195:6557/Log; #本机的9999后端api接口,留意这个端口是要和yaml文件的端口一致           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;       }                  location /DownLoad {                           #后端接口设置           proxy_pass http://120.77.144.195:6557/DownLoad; #本机的9999后端api接口,留意这个端口是要和yaml文件的端口一致           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;       }      

  • 部分页面 Data 下面的图片单独访问没问题,在页面中访问就会跨域(调用腾讯地图,并更换底图的图片),修改如下
  location /Data {             add_header 'Access-Control-Allow-Origin' "$http_origin" always;              add_header 'Access-Control-Allow-Credentials' 'true' always;              add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always;              add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-  Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;           #后端接口设置           proxy_pass http://120.77.144.195:6557/Data; #本机的9999后端api接口,留意这个端口是要和yaml文件的端口一致           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;       }

  • 完备的  nginx.conf  如下:
root@VERDE-SICC-APPLICATION1:~# cat /etc/nginx/nginx.conf user www-data;worker_processes auto;pid /run/nginx.pid;#include /etc/nginx/modules-enabled/*.conf;events {        worker_connections 768;        # multi_accept on;}http{#server{#                listen 80;#                server_name  cloud.hnverde.com;               #                location / {#                        root /usr/share/nginx/html;#                        try_files $uri $uri/ @router; #                       index index.html;#                }#}server {    listen 80;    #请填写绑定证书的域名    server_name cloud.hnverde.com;     #把http的域名哀求转成https    return 301 https://$host$request_uri; }        ##        # Basic Settings        ##        sendfile off;        tcp_nopush on;        tcp_nodelay on;        keepalive_timeout 65;        types_hash_max_size 2048;        # server_tokens off;        # server_names_hash_bucket_size 64;        # server_name_in_redirect off;        include /etc/nginx/mime.types;        default_type application/octet-stream;server{        ##        # SSL Settings        ##        listen 443 ssl;        server_name cloud.hnverde.com;        root /usr/share/nginx/html;        index index.html index.htm;        ssl_certificate cert/8444101_cloud.hnverde.com.pem;        ssl_certificate_key cert/8444101_cloud.hnverde.com.key;        ssl_session_timeout  5m;        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;        ssl_prefer_server_ciphers on;        location / {        #网站主页路径。此路径仅供参考,具体请您按照现实目次利用。         #比方,您的网站主页在 Nginx 服务器的 /etc/www 目次下,则请修改 root 反面的 html 为 /etc/www。        root /usr/share/nginx/html;        index index.html index.htm;    }         location /api {                           #后端接口设置           proxy_pass http://120.77.144.195:6557/api; #本机的9999后端api接口,留意这个端口是要和yaml文件的端口一致           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;       }  location /Data {                           #后端接口设置           proxy_pass http://120.77.144.195:6557/Data; #本机的9999后端api接口,留意这个端口是要和yaml文件的端口一致           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;       }          location /Log {                           #后端接口设置           proxy_pass http://120.77.144.195:6557/Log; #本机的9999后端api接口,留意这个端口是要和yaml文件的端口一致           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;       }                              location /DownLoad {                           #后端接口设置           proxy_pass http://120.77.144.195:6557/DownLoad; #本机的9999后端api接口,留意这个端口是要和yaml文件的端口一致           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;       }                  ##        # Logging Settings        ##        access_log /var/log/nginx/access.log;        error_log /var/log/nginx/error.log;        ##        # Gzip Settings        ##        gzip on;        # gzip_vary on;        # gzip_proxied any;        # gzip_comp_level 6;        # gzip_buffers 16 8k;        # gzip_http_version 1.1;        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;        ##        # Virtual Host Configs        ##        #include /etc/nginx/conf.d/*.conf;        #include /etc/nginx/sites-enabled/*;}}#mail {#       # See sample authentication script at:#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript# #       # auth_http localhost/auth.php;#       # pop3_capabilities "TOP" "USER";#       # imap_capabilities "IMAP4rev1" "UIDPLUS";# #       server {#               listen     localhost:110;#               protocol   pop3;#               proxy      on;#       }# #       server {#               listen     localhost:143;#               protocol   imap;#               proxy      on;#       }#}11. 上传限定


  • nginx.conf 参加如下设置
client_max_body_size 2000M; #答应客户端哀求的最大单文件字节数client_body_buffer_size 128k; #缓冲区署理缓冲用户端请>求的最大字节数fastcgi_intercept_errors on;

  • nginx.conf  完备设置如下:
user www-data;worker_processes auto;pid /run/nginx.pid;#include /etc/nginx/modules-enabled/*.conf;events {        worker_connections 768;        # multi_accept on;}http{#server{#                listen 80;#                server_name  cloud.hnverde.com;               #                location / {#                        root /usr/share/nginx/html;#                        try_files $uri $uri/ @router; #                       index index.html;#                }#}server {    listen 80;    #请填写绑定证书的域名    server_name cloud.hnverde.com;     #把http的域名哀求转成https    return 301 https://$host$request_uri; }        ##        # Basic Settings        ##        client_max_body_size 2000M; #答应客户端哀求的最大单文件字节数client_body_buffer_size 128k; #缓冲区署理缓冲用户端请>求的最大字节数fastcgi_intercept_errors on;        sendfile off;        tcp_nopush on;        tcp_nodelay on;        keepalive_timeout 65;        types_hash_max_size 2048;        # server_tokens off;        # server_names_hash_bucket_size 64;        # server_name_in_redirect off;        include /etc/nginx/mime.types;        default_type application/octet-stream;server{        ##        # SSL Settings        ##        listen 443 ssl;        server_name cloud.hnverde.com;        root /usr/share/nginx/html;        index index.html index.htm;        ssl_certificate cert/8444101_cloud.hnverde.com.pem;        ssl_certificate_key cert/8444101_cloud.hnverde.com.key;        ssl_session_timeout  5m;        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;        ssl_prefer_server_ciphers on;        location / {        #网站主页路径。此路径仅供参考,具体请您按照现实目次利用。         #比方,您的网站主页在 Nginx 服务器的 /etc/www 目次下,则请修改 root 反面的 html 为 /etc/www。        root /usr/share/nginx/html;        index index.html index.htm;    }         location /api {                           #后端接口设置           proxy_pass http://120.77.144.195:6557/api; #本机的9999后端api接口,留意这个端口是要和yaml文件的端口一致           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;       }  location /Data {             add_header 'Access-Control-Allow-Origin' "$http_origin" always;              add_header 'Access-Control-Allow-Credentials' 'true' always;              add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always;              add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-  Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;           #后端接口设置           proxy_pass http://120.77.144.195:6557/Data; #本机的9999后端api接口,留意这个端口是要和yaml文件的端口一致           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;       }          location /Log {                           #后端接口设置           proxy_pass http://120.77.144.195:6557/Log; #本机的9999后端api接口,留意这个端口是要和yaml文件的端口一致           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;       }                              location /DownLoad {                           #后端接口设置           proxy_pass http://120.77.144.195:6557/DownLoad; #本机的9999后端api接口,留意这个端口是要和yaml文件的端口一致           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;       }                  ##        # Logging Settings        ##        access_log /var/log/nginx/access.log;        error_log /var/log/nginx/error.log;        ##        # Gzip Settings        ##        gzip on;        # gzip_vary on;        # gzip_proxied any;        # gzip_comp_level 6;        # gzip_buffers 16 8k;        # gzip_http_version 1.1;        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;        ##        # Virtual Host Configs        ##        #include /etc/nginx/conf.d/*.conf;        #include /etc/nginx/sites-enabled/*;}}#mail {#       # See sample authentication script at:#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript# #       # auth_http localhost/auth.php;#       # pop3_capabilities "TOP" "USER";#       # imap_capabilities "IMAP4rev1" "UIDPLUS";# #       server {#               listen     localhost:110;#               protocol   pop3;#               proxy      on;#       }# #       server {#               listen     localhost:143;#               protocol   imap;#               proxy      on;#       }#}
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-10-18 22:32, Processed in 0.159148 second(s), 35 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表