Nginx是一個開源且高性能、可靠的HTTP中間件、代理服務。
2. 常見的HTTP服務httpd - Apache
IIS - 微軟
GWE - Google
tomcat - Sun
二、為什么選擇Nginx1. IO多路復用epoll什么是IO多路復用多個描述符的I/O操作都能在一個線程內并發交替地順序完成,這就叫I/O多路復用,這里的“復用”指的是復用同一個線程。
什么是epollIO多路服用的實現方式:select、poll、epollselect基本原理:
select 函數監視的文件描述符分3類,分別是writefds、readfds、和exceptfds。調用后select函數會阻塞,直到有描述符就緒(有數據 可讀、可寫、或者有except),或者超時(timeout指定等待時間,如果立即返回設為null即可),函數返回。當select函數返回后,可以通過遍歷fdset,來找到就緒的描述符。
select缺點:
1.能夠監視文件描述符的數量存在最大限制。
2.線性掃描效率低下。
基本原理:
epoll支持水平觸發和邊緣觸發,最大的特點在于邊緣觸發,它只告訴進程哪些fd剛剛變為就緒態,并且只會通知一次。還有一個特點是,epoll使用“事件”的就緒通知方式,通過epoll_ctl注冊fd,一旦該fd就緒,內核就會采用類似callback的回調機制來激活該fd,epoll_wait便可以收到通知。
epoll的優點:
1.沒有最大并發連接的限制,能打開的FD的上限遠大于1024(1G的內存上能監聽約10萬個端口)。
2.效率提升,不是輪詢的方式,不會隨著FD數目的增加效率下降。
3.內存拷貝,利用mmap()文件映射內存加速與內核空間的消息傳遞;即epoll使用mmap減少復制開銷。
CPU親和性(affinity)是一種把CPU核心和Nginx工作進程綁定方式,把每個worker進程固定在一個CPU上執行,減少CPU的cache miss,獲得更好的性能。
4. sendfile三、Nginx的快速搭建和基本參數(CentOS7)1. yum方式安裝【參考】創建/etc/yum.repos.d/nginx.repo文件,并輸入如下內容[nginx]name=nginx repobaseurl=http://nginx.org/packages/mainline/OS/OSRELEASE/$basearch/gpgcheck=0enabled=1OS 可選值有 centos 和 rhel。
[root~]# nginx -vnginx version: nginx/1.14.02. 編譯參數詳解查看nginx安裝時的編譯參數
nginx -V
[root~]# nginx -Vnginx version: nginx/1.14.0built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)built with OpenSSL 1.0.2k-fips 26 Jan 2017TLS SNI support enabledconfigure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_html' target='_blank'>static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt= -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC --with-ld-opt= -Wl,-z,relro -Wl,-z,now -pie安裝編譯參數詳解【參考】編譯選項作用--prefix=/etc/nginx配置文件目錄--sbin-path=/usr/sbin/nginx可執行文件名稱和所在目錄--modules-path=/usr/lib64/nginx/modulesnginx動態模塊的安裝目錄--conf-path=/etc/nginx/nginx.conf主配置文件名稱和所在目錄--error-log-path=/var/log/nginx/error.log全局錯誤日志文件名稱和所在目錄--http-log-path=/var/log/nginx/access.logHTTP服務器的主請求日志文件的名稱和所在目錄--pid-path=/var/run/nginx.pidnginx.pid所在目錄,這是儲存主進程的進程ID文件--lock-path=/var/run/nginx.locknginx.lock所在目錄--http-client-body-temp-path=/var/cache/nginx/client_temp
rpm -ql nginx
[root~]# rpm -ql nginx/etc/logrotate.d/nginx/etc/nginx/etc/nginx/nginx.conf/etc/nginx/conf.d/etc/nginx/conf.d/default.conf/etc/nginx/fastcgi_params/etc/nginx/scgi_params/etc/nginx/uwsgi_params/etc/nginx/koi-utf/etc/nginx/koi-win/etc/nginx/win-utf/etc/nginx/mime.types/etc/sysconfig/nginx/etc/sysconfig/nginx-debug/usr/lib/systemd/system/nginx-debug.service/usr/lib/systemd/system/nginx.service/usr/lib64/nginx/usr/lib64/nginx/modules/etc/nginx/modules/usr/sbin/nginx/usr/sbin/nginx-debug/usr/share/doc/nginx-1.14.0/usr/share/doc/nginx-1.14.0/COPYRIGHT/usr/share/man/man8/nginx.8.gz/usr/share/nginx/usr/share/nginx/html/usr/share/nginx/html/50x.html/usr/share/nginx/html/index.html/var/cache/nginx/var/log/nginx/usr/libexec/initscripts/legacy-actions/nginx/usr/libexec/initscripts/legacy-actions/nginx/check-reload/usr/libexec/initscripts/legacy-actions/nginx/upgrade默認路徑類型作用/etc/logrotate.d/nginx配置文件Nginx日志輪轉,用于logrotate服務的日志切割/etc/nginx
Nginx的master進程檢查配置文件的正確性,若是錯誤則返回錯誤信息,nginx繼續采用原配置文件進行工作(因為worker未受到影響)
Nginx啟動新的worker進程,采用新的配置文件
Nginx將新的請求分配新的worker進程
Nginx等待以前的worker進程的全部請求都返回后,關閉相關worker進程
重復上面過程,直到全部舊的worker進程都被關閉掉
以上就是本文的全部內容,希望對大家的學習有所幫助,更多相關內容請關注PHP !
相關推薦:
Nginx負載調度器+雙Tomcat負載及會話共享+MySQL后端數據庫
使用nginx在一臺服務器部署多個Web Server
以上就是快速搭建Nginx及其基本參數的配置的詳細內容,PHP教程
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答
圖片精選