2016年7月8日 星期五

在 CentOS7/RHEL7 上架設 Nginx Web Server(四)

設定目標:
  • 設定 Nginx Web Server,架設 Reverse Proxy Server 服務!

事前準備:
  • 請先參考這一篇文件,架設好 Nginx Web Server!

快速設定流程:
  1. 編寫 Nginx 預設設定檔:
    #vi /etc/nginx/nginx.conf
    (註解以下設定:)
    # server {
       :
       :
    #  }
    
  2. 編寫 for proxy 的設定檔:
    #vi /etc/nginx/conf.d/proxy.conf
    upstream proxy {
        server 192.168.5.61:80;
    }
    
    server {
        listen      80 default;
        server_name www.example.com;
    
        access_log  /var/log/nginx/jenkins.access.log;
        error_log   /var/log/nginx/jenkins.error.log;
    
        proxy_buffers 16 64k;
        proxy_buffer_size 128k;
    
        location / {
            proxy_pass  http://proxy;
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
            proxy_redirect off;
    
            proxy_set_header    Host            $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;
        }
    }
    
  3. 啟動 Nginx :
    #systemctl enable nginx.service
    #systemctl start nginx.service
    
  4. 啟動防火牆:
    #firewall-cmd --permanent --add-service=http
    #firewall-cmd --reload
    

參考文獻:

  1. https://www.nginx.com/resources/admin-guide/reverse-proxy/
  2. http://shazi.info/centos-6-%E5%BB%BA%E7%AB%8B-nginx-reverse-proxy/
  3. https://www.twstar.biz/43151.html
  4. http://icodding.blogspot.tw/2015/08/nginx.html
  5. https://snippetinfo.net/media/671/
  6. https://deviantengineer.com/2015/05/nginx-reverseproxy-centos7/
  7. https://www.rosehosting.com/blog/install-and-configure-jenkins-with-nginx-as-a-reverse-proxy-on-centos-7/