How to configure SSL access locally on Nginx

王林
Release: 2023-05-26 16:28:06
forward
1265 people have browsed it

    1. Configuration steps

    1.1 Generate certificate

    keytool -genkey -v -alias nginx -keyalg RSA -keystore nginx.keystore -validity 36500
    Copy after login

    alias alias is nginx

    keystore file For nginx.keystore

    validity is valid for 36500 days

    How to configure SSL access locally on Nginx

    Follow the above figure to help us generate the nginx.keystore file

    1.2 Convert certificate format

    JKS2PFX.bat nginx.keystore 123456 nginx exportfile .
    Copy after login

    This JKS2PFX.bat is a tool, the download address is

    nginx.keystore, which is the file we just generated

    123456 is the password we just generated the nginx.keystore file and set

    nginx is the alias we just set

    exportfile is the file name we want to generate

    ., the directory where the ssl certificate is generated, indicating the current folder

    How to configure SSL access locally on Nginx

    运行方式:
    JKS2PFX.bat <KeyStore文件> <KeyStore密码> <Alias别名> <导出文件名> [目录]
    Copy after login

    The conversion will generate:

    How to configure SSL access locally on Nginx

    We will copy the exportfile.crt and exportfile.key files to the ssl directory of nginx's conf

    How to configure SSL access locally on Nginx

    1.3 Configure nginx

    server {
        listen 443 ssl;
        server_name localhost;
        ssl_certificate ssl/exportfile.crt;
        ssl_certificate_key ssl/exportfile.key; 
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m; 
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;
    
        location / {
            proxy_set_header Host       $host;
            proxy_pass http://localhost/;
        }
    }
    Copy after login

    How to configure SSL access locally on Nginx

    After configuration, use nginx -s reload to restart.

    This configuration supports http and https at the same time

    How to configure SSL access locally on Nginx

    means that sslhas been configured

    1.4 Note

    nginx needs to support ssl. If it does not support it, you need to add a security module.

    How to configure SSL access locally on Nginx

    • with-http_ssl_module: ssl module, if not, you can install it yourself

    The above is the detailed content of How to configure SSL access locally on Nginx. For more information, please follow other related articles on the PHP Chinese website!

    Related labels:
    source:yisu.com
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!