nginx ssl http auth proxy pass howto

 

nginx編譯支持SSLhtml

 

  
  
           
  
  
  1. ./configure --with-http_ssl_module 

生成ssl證書nginx

 

  
  
           
  
  
  1. cd /usr/local/nginx/conf 
  2. openssl genrsa -des3 -out server.key 1024 
  3. openssl req -new -key server.key -out server.csr 
  4. cp server.key server.key.org 
  5. openssl rsa -in server.key.org -out server.key 
  6. openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt 

nginx啓用sslsession

 

  
  
           
  
  
  1. ssl on; 
  2. ssl_certificate /usr/local/nginx/conf/server.crt; 
  3. ssl_certificate_key /usr/local/nginx/conf/server.key; 

生成htpasswd文件app

 

  
  
           
  
  
  1. htpasswd -c /usr/local/nginx/conf/passwd test 

nginx啓用httpauthide

 

  
  
           
  
  
  1. auth_basic              "111111"; 
  2. uth_basic_user_file  /usr/local/nginx/conf/passwd; 

nginx啓用反向代理spa

 

  
  
           
  
  
  1. proxy_pass   https://127.0.0.1:10000; 

最後的nginx.conf以下代理

 

  
  
           
  
  
  1. user  nobody; 
  2. worker_processes  1; 
  3. events { 
  4.     worker_connections  1024; 
  5. http { 
  6.     include       mime.types; 
  7.     default_type  application/octet-stream; 
  8.     sendfile        on; 
  9.     keepalive_timeout  65; 
  10.     gzip  on; 
  11.     server { 
  12.         listen       443; 
  13.         server_name  localhost; 
  14. ssl                  on; 
  15.        ssl_certificate      server.crt; 
  16.       ssl_certificate_key  server.key; 
  17.         ssl_session_timeout  5m; 
  18.         ssl_protocols  TLSv1; 
  19.         ssl_ciphers  HIGH:!aNULL:!MD5; 
  20.         ssl_prefer_server_ciphers   on; 
  21.         location / { 
  22.            root   html; 
  23.             index  index.html index.htm; 
  24.                         auth_basic              "111111"; 
  25.                         auth_basic_user_file  /usr/local/nginx/conf/passwd; 
  26.             proxy_pass   https://127.0.0.1:10000; 
  27.         } 
  28.         error_page   500 502 503 504  /50x.html; 
  29.     } 
相關文章
相關標籤/搜索