served 部份就用 example 來測試。所以重點就是 nginx 左為一個 https reverese proxy 的設定..
- 啟動 https
- 將 https 轉為 http ,送到 served。(reverse proxy)
- 啟動 basic authentication, 要求登入
nginx 要啟動 https,要先有 ssl 憑證。
因為是local 測試用,所以就自己產生一個就好。
跟 ref 的網站說明一樣,用 openssl 產生:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt其中 common name (FQDN) 就用 ip address : 172.16.200.11 這樣就可以。
產生 test.crt, test.key 兩個檔。放到 /etc/nginx/ssl/ 下。
然後修改 /etc/nginx/sites-available/default
加入:
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl_certificate /etc/nginx/ssl/test.crt;
ssl_certificate_key /etc/nginx/ssl/test.key;
重新啟動,測試一下,應該能看到 nginx 的 welcome pagereverse proxy 部份好像不分 https 還是 http,一樣是在 location 區塊加上
proxy_pass http://localhost:8123/;
這樣舊可以。啟動 served 的 example...
/served/bin$ ./eg_hello_world Try this example with: curl http://localhost:8123/hello這樣在其他機器上用 https://172.16.200.11/hello 舊可以看到 ...
最後就是啟動 basic authentication
需要有 user:password 檔。
簡單的方法是用 apache2-utils 的 htpasswd 產生。
但是在 embedd system 要 cross-build htpasswd 很麻煩,就用 openssl 來產生。
-- openssl 在啟動 openssl-server 時會一起build
這裡提供了一堆產生 password 的方法。都不用 apache2-utils 的 htpasswd
這裡用一般的,openssl passwd 的方法:
sudo sh -c "echo -n 'sammy:' >> /etc/nginx/.htpasswd" sudo sh -c "openssl passwd -apr1 >> /etc/nginx/.htpasswd"* password 好像要6 個 character,用 1234 個的話每次都會 login fail
這樣舊產生好 user: sammy 的 password 。
然後在 nginx 的 location 區段加上
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
重新啟動 nginx 後,在 https://172.16.200.11/hello 就會跳出login 對話盒,輸入username, password 就會出現 served 的 hello world 字樣。設定完後,可以用 openssl 來看你的 CA chain 和 TLS version....
$ openssl s_client -connect www.godaddy.com:443
...
Certificate chain
0 s:/C=US/ST=Arizona/L=Scottsdale/1.3.6.1.4.1.311.60.2.1.3=US
/1.3.6.1.4.1.311.60.2.1.2=AZ/O=GoDaddy.com, Inc
/OU=MIS Department/CN=www.GoDaddy.com
/serialNumber=0796928-7/2.5.4.15=V1.0, Clause 5.(b)
i:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc.
/OU=http://certificates.godaddy.com/repository
/CN=Go Daddy Secure Certification Authority
/serialNumber=07969287
1 s:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc.
/OU=http://certificates.godaddy.com/repository
/CN=Go Daddy Secure Certification Authority
/serialNumber=07969287
i:/C=US/O=The Go Daddy Group, Inc.
/OU=Go Daddy Class 2 Certification Authority
2 s:/C=US/O=The Go Daddy Group, Inc.
/OU=Go Daddy Class 2 Certification Authority
i:/L=ValiCert Validation Network/O=ValiCert, Inc.
/OU=ValiCert Class 2 Policy Validat$ openssl s_client -connect www.godaddy.com:443
...
Certificate chain
0 s:/C=US/ST=Arizona/L=Scottsdale/1.3.6.1.4.1.311.60.2.1.3=US
/1.3.6.1.4.1.311.60.2.1.2=AZ/O=GoDaddy.com, Inc
/OU=MIS Department/CN=www.GoDaddy.com
/serialNumber=0796928-7/2.5.4.15=V1.0, Clause 5.(b)
i:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc.
/OU=http://certificates.godaddy.com/repository
/CN=Go Daddy Secure Certification Authority
/serialNumber=07969287
1 s:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc.
/OU=http://certificates.godaddy.com/repository
/CN=Go Daddy Secure Certification Authority
/serialNumber=07969287
i:/C=US/O=The Go Daddy Group, Inc.
/OU=Go Daddy Class 2 Certification Authority
2 s:/C=US/O=The Go Daddy Group, Inc.
/OU=Go Daddy Class 2 Certification Authority
i:/L=ValiCert Validation Network/O=ValiCert, Inc.
/OU=ValiCert Class 2 Policy Validation Authority
/CN=http://www.valicert.com//emailAddress=info@valicert.comion Authority
/CN=http://www.valicert.com//emailAddress=info@valicert.com
沒有留言:
張貼留言