2019年6月4日 星期二

nginx-ssl @ docker

Ref: http://www.ruanyifeng.com/blog/2018/02/nginx-docker.html

ASUS X450 @ Windows 10 x64 Prof
Docker version 18.09.2, build 6247962
openssl http://slproweb.com/products/Win32OpenSSL.html

1. Install openssl
2. Prepare certificate and key files
D:\ssl0604>"C:\Program Files\OpenSSL-Win64\bin\openssl.exe"
OpenSSL> req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem
OpenSSL> x509 -text -noout -in certificate.pem
3. copy *.pem into certs fold
4. docker run -d -p 8080:80 -p 8081:443 --name mynginx nginx
5. copy configuration fold
docker cp mynginx:/etc/nginx .
6. Modify conf.d/default.config
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
server {
    listen 443 ssl http2;
    server_name  localhost;

    ssl                      on;
    ssl_certificate          /etc/nginx/certs/certificate.pem;
    ssl_certificate_key      /etc/nginx/certs/key.pem;

    ssl_session_timeout  5m;

    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers   on;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
}
7. docker cp certs/. mynginx:/etc/nginx/certs/.
8. docker cp default.conf mynginx:/etc/nginx/conf.d/default.conf
9. docker exec -it mynginx  /bin/bash
10. nginx -s stop (logout automatically)
11. docker start mynginx
12 chech https://ip:8081/





沒有留言:

張貼留言