close

補充資料

 


Step1. http 重新導向 https動作

 

    server {

        listen       80 default_server;

        #listen       [::]:80 default_server;

        server_name  dockeregistry.***.com.tw;

        #root         /usr/share/nginx/html;

 

        # Load configuration files for the default server block.

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

 

        return 301 https://$server_name$request_uri;

}

 

 


Step 1.5 因為目前Nginx不吃chain的設定,Httpd還有支援。

所以若是憑證有server.cer(crt) / uca.cer(crt) / serve.key 。是3個檔案的話。

需要將前面兩隻合併成一隻 cer(crt)憑證檔。

server.cer 憑證 / uca.cer  Chain憑證 / server.key 金鑰

合併作法

#cat server.cer uca.cer > server.chain.cer

 

 


Step 2. 開啟Nginx https設定 / 並設定導頁

放入憑證(放入crt 或者 cer都可以)。以及設定轉PORTTCP-5000

這邊的動作是將註解拿掉而已

 

   server {

        listen       443 ssl http2 default_server;

#        listen       [::]:443 ssl http2 default_server;

        server_name  dockeregistry.***.com.tw;

#        root         /usr/share/nginx/html;

#

        ssl_certificate "/etc/nginx/server.chain.cer";

        ssl_certificate_key "/etc/nginx/server.key";

        ssl_session_cache shared:SSL:1m;

        ssl_session_timeout  10m;

        ssl_ciphers HIGH:!aNULL:!MD5;

        ssl_prefer_server_ciphers on;

#

#        # Load configuration files for the default server block.

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

#

        location / {

         if ($http_user_agent ~ "^(docker\/1\.(3|4|5(?!\.[0-9]-dev))|Go ).*\$" ) {

            return 404;

        }

 

        auth_basic "Registry";

        auth_basic_user_file  /opt/dockerRegistry/conf/registry.htpasswd;

        #add_header Docker-Distribution-Api-Version  registry/2.0    always;

 

        proxy_pass http://dockerservice;

        proxy_set_header  Host              $http_host;

        proxy_set_header  X-Real-IP         $remote_addr;

        proxy_set_header  X-Forwarded-For   $proxy_add_x_forwarded_for;

        proxy_set_header  X-Forwarded-Proto https;

        proxy_set_header  X-Original-URI    $request_uri;

        proxy_set_header  Docker-Distribution-Api-Version   registry/2.0;

        proxy_read_timeout                  900;

        }

}

 


Step 3. Nginx 轉頁設定

這邊想把連進來根目錄網頁的使用者全部導到/v2網頁去。

關於導頁部份。我們使用rewrite來達成。

加入  rewrite / /v2/ break;

 location / {

         if ($http_user_agent ~ "^(docker\/1\.(3|4|5(?!\.[0-9]-dev))|Go ).*\$" ) {

            return 404;

        }

 

        auth_basic "Registry";

        auth_basic_user_file  /opt/dockerRegistry/conf/registry.htpasswd;

        #add_header Docker-Distribution-Api-Version  registry/2.0    always;

 

        proxy_pass http://dockerservice;

        proxy_set_header  Host              $http_host;

        proxy_set_header  X-Real-IP         $remote_addr;

        proxy_set_header  X-Forwarded-For   $proxy_add_x_forwarded_for;

        proxy_set_header  X-Forwarded-Proto https;

        proxy_set_header  X-Original-URI    $request_uri;

        proxy_set_header  Docker-Distribution-Api-Version   registry/2.0;

        proxy_read_timeout                  900;

 

        rewrite / /v2/ break;

        }

 


後記:

關於nginxPort 以及 導頁方面的設定,

我是將導Port這件事情交由 Proxypass這個方法去達成。

導頁是交由rewrite去完成。

 

關於參考網址中有提到nginx rewrite很重要的類型。這邊要注意一下

last : 通常不會寫在location當中,表示完成導頁後。瀏覽器頁面URL不變

break: 通常寫在location當中,表示對到這個規則成立後,就不會再往下配對。瀏覽器頁面URL不變

redirect: 302的臨時導向,瀏覽器頁面導向後URL變更。

permanent: 301的永久導向,瀏覽器頁面導向後URL變更。

nginx設定很方便。也有許多更進階的使用方式,

 

再讓大家自行測試看看。

 

 


參考網址:

https://code.yidas.com/nginx_http-to-https/

https://www.denpe.com/nginx-ip-301-www/

https://blog.longwin.com.tw/2015/12/nginx-ssl-https-ca-setup-rating-a-2015/

http://xstarcd.github.io/wiki/sysadmin/nginx_proxy_redirect.html

https://xuexb.com/post/nginx-url-rewrite.html

 

 

arrow
arrow
    全站熱搜

    IT001 發表在 痞客邦 留言(0) 人氣()