1,nginx 安裝發布yum源html
下載相應的nginx-XXX.tar.gz文件node
須要安裝相應的軟件包pcrenginx
2,若是須要啟用ssl還須要下載相應的軟件包openssl-1.0.1j.tar.gz
git
tar -zxvf openssl-1.0.1j.tar.gzgithub
mv openssl-1.0.1j /usr/local/openssldocker
解壓便可便可,不須要安裝shell
3,生成證書,下載一個生成證書的小工具
緩存
ssl.ca-0.1.tar.gz服務器
tar -zxvf ssl.ca-0.1.tar.gz # ./new-root-ca.sh (生成根證書)
這樣就生成了ca.key和ca.crt兩個文件;網絡
下面還要爲咱們的服務器生成一個證書:
# ./new-server-cert.sh server (這個證書的名字是server)
這樣就生成了server.csr和server.key這兩個文件。
還須要簽署一下才能使用的:
# ./sign-server-cert.sh server CA signing: server.csr ->; server.crt: Using configuration from ca.config Enter pass phrase for ./ca.key: (輸入上面設置的根證書密碼)
這樣生成的三個文件為
nginx.vmware.xx.crt
nginx.vmware.xx.csr
nginx.vmware.xx.key
將*.crt和*.key 拷貝到相應的位置;
4,安裝nginx使其支持ssl 並且安裝ngx-fancyindex-master
openssl不須要安裝
tar -zxvf nginx-XXX.tar.gz mv ngx-fancyindex-master nginx-1.6.2/ ./configure --user=nginx \ --group=nginx \ --prefix=/usr/local/nginx \ --with-http_ssl_module \ --with-http_stub_status_module make&&make install
5,配置nginx.conf文件
以下面的文件
server { server_name nginx.vmware.xx; rewrite ^(.*)$ https://nginx.vmware.xx$1 permanent; } server { listen 10.207.237.110:443 ssl; server_name nginx.vmware.xx; ssl_certificate /usr/local/nginx/cert/nginx.vmware.xx.crt; ssl_certificate_key /usr/local/nginx/cert/nginx.vmware.xx.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { # autoindex on; # autoindex_exact_size on; # autoindex_localtime on; fancyindex on; fancyindex_exact_size off; fancyindex_localtime on; # fancyindex_footer footer.html; # fancyindex_header header.html; root html; index index.html index.htm; } } server { listen 8080; server_name 10.207.237.110; location /ngx_status { stub_status on; access_log off; } }
重啟服務便可;
sbin/nginx kill -HUP nginx-pid(nginx進程ID) sbin/nginx kill -INT nginx-pid(硬性關閉) sbin/nginx kill -QUIT nginx-pid(優雅的退出) sbin/nginx kill -USR1 nginx-pid(日誌的切分,使其使用新的日誌) sbin/nginx kill -USR2 nginx-pid(升級使用,) sbin/nginx kill -WATCH nginx-pid(舊的PID)
nginx -s reload 從新加載文件
5,nginx性能優化;
keepalive_timeout 0; gzip on; gzip_buffers 32 4K; gzip_min_length 1000; gzip_comp_level 6; gzip_http_version 1.1; gzip_types application/x-redhat-package-manager text/plain application/xml;
location /ngx_status { stub_status on; access_log off; expires 1d; #網站緩存1天 allow 10.206.21.104; deny all; }
worker_processes 6; worker_rlimit_nofile 65535;
nginx配置示例
#daemon off; # 使用的用戶和組 user www www; # 指定工做進程數(通常等於CPU總核數) worker_processes auto; # 指定錯誤日誌的存放路徑,錯誤日誌記錄級別選項爲:[debug | info | notic | warn | error | crit] error_log /var/log/nginx_error.log error; #指定pid存放的路徑 #pid logs/nginx.pid; # 指定文件描述符數量 worker_rlimit_nofile 51200; events { # 使用的網絡I/O模型,Linux推薦epoll;FreeBSD推薦kqueue use epoll; # 容許的最大鏈接數 worker_connections 51200; multi_accept on; } http { include mime.types; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$upstream_addr"'; access_log /var/log/nginx_access.log main; # 服務器名稱哈希表的桶大小,該默認值取決於CPU緩存 server_names_hash_bucket_size 128; # 客戶端請求的Header頭緩衝區大小 client_header_buffer_size 32k; large_client_header_buffers 4 32k; # 啓用sendfile()函數 sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; upstream registry { server 127.0.0.1:5000; } server { listen 443; server_name 192.168.2.114; ssl on; ssl_certificate /etc/nginx/ssl/nginx.crt; ssl_certificate_key /etc/nginx/ssl/nginx.key; client_max_body_size 0; # disable any limits to avoid HTTP 413 for large image uploads # required to avoid HTTP 411: see Issue #1486 (https://github.com/docker/docker/issues/1486) chunked_transfer_encoding on; location / { auth_basic "registry"; auth_basic_user_file /opt/nginx/conf/.htpasswd; root html; index index.html index.htm; proxy_pass http://registry; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Authorization ""; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 8k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; #若是系統很忙的時候能夠申請更大的proxy_buffers 官方推薦*2 proxy_temp_file_write_size 64k; #proxy緩存臨時文件的大小 } location /_ping { auth_basic off; proxy_pass http://registry; } location /v1/_ping { auth_basic off; proxy_pass http://registry; } } }
<!-- footer START --> <div id="footer"> <a id="gotop" href="#" onclick="MGJS.goTop();return false;">回到頂部</a> <a id="powered" href="http://mirror.vmware.xx/">WordPress</a> <div id="copyright"> 版權全部 © 2011-2013 SIDC-MIS </div> <div id="themeinfo"> <a href="http://mirror.vmware.xx/about/">關於咱們</a> | <a href="http://mirror.vmware.xx/">網站導航</a> | <a href=http://mirror.vmware.xx/">網站地圖</a> |<a rel="nofollow" href="http://mirror.vmware.xx">豫ICP備1100xxxx號-1</a> </div> </div> <!-- footer END --> 版權全部
nginx啓動腳本
#!/bin/sh # # nginx - this script starts and stops the nginx daemin # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /usr/local/nginx/conf/nginx.conf # pidfile: /usr/local/nginx/logs/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" lockfile=/var/lock/subsys/nginx start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac