天天看點

nginx簡介與安裝配置1:nginx簡介:2:nginx特性:3.nginx安裝:4:nginx的配置檔案:

1:nginx簡介:

是個伺服器,主要是php常用到的伺服器。

Nginx ("engine x") 是一個高性能的 HTTP 和 反向代理 伺服器,也是一個 IMAP/POP3/SMTP 伺服器。 Nginx 是由 Igor Sysoev 為俄羅斯通路量第二的 Rambler.ru 站點開發的,第一個公開版本0.1.0釋出于2004年10月4日。其将源代碼以類BSD許可證的形式釋出,因它的穩定性、豐富的功能集、示例配置檔案和低系統資源的消耗而聞名。2011年6月1日,nginx 1.0.4釋出。

Nginx是一款輕量級的Web 伺服器/反向代理伺服器及電子郵件(IMAP/POP3)代理伺服器,并在一個BSD-like 協定下發行。由俄羅斯的程式設計師Igor Sysoev所開發,供俄國大型的入口網站及搜尋引擎Rambler(俄文:Рамблер)使用。其特點是占有記憶體少,并發能力強,事實上nginx的并發能力确實在同類型的網頁伺服器中表現較好,中國大陸使用nginx網站使用者有:百度、新浪、網易、騰訊等。

優點是可以在大多數 Unix like OS 上編譯運作,并有 Windows 移植版。 Nginx 的1.4.0穩定版已經于2013年4月24日釋出,一般情況下,對于建立站點,建議使用最新穩定版作為生産版本,已有站點的更新急迫性不高。Nginx 的源代碼使用 2-clause BSD-like license。

Nginx 是一個很強大的高性能Web和反向代理伺服器,它具有很多非常優越的特性:nginx有社群版,商業版/企業版(nginx_plus)

2:nginx特性:

2.1高可靠性:

架構模式:master/worker

2.2熱部署:

不停止服務,而更新配置檔案,更換日志檔案,更新伺服器版本(平緩遷移)

低記憶體消耗。10000個keep-alive連接配接模式下的非活動連接配接,僅需要消耗2.5M記憶體。

2.3:基本功能:

靜态資源的web伺服器:

http協定的反向代理服務:

Pop3,smpt,imap4等郵件協定的反向代理

能緩存打開的檔案(中繼資料),支援FastCGI(php_fpm),uWSGI(pythonweb framework)等協定。

子產品化(非DSO機制),過濾器zip,SSI,SSL;

2.4:web服務相關功能:

虛拟主機(server),keeyalive,通路日志(支援基于日志緩沖提高其性能),url rewrite,

路徑别名,基于ip及使用者的通路控制,速率限制,并發數限制。

2.5:nginx基本架構:

nginx簡介與安裝配置1:nginx簡介:2:nginx特性:3.nginx安裝:4:nginx的配置檔案:

模式;Master/worker

一個master程序,可生成一個或多個worker程序;

事件驅動:epoll(linux),kqueue(FreeBSD),/dev/poll(Solarls)

消息通知:select,poll,rt signals

支援sendfile,sendfile64

支援AIO,mmap

master:加載配置檔案,管理worker程序,平滑更新,,

worker:http服務,http代理,fastcgi代理。。。

nginx子產品類型:

核心子產品:coremodule

Standard HTTP modules(标準的)

Options HTTP modules(可選的)

Mail modules

第三方子產品(需要在編譯時,手動指明加載方式加載)

nginx用來做什麼:

靜态資源的web伺服器;

http伺服器的反向代理;

什麼是代理;

正向:站着用戶端前端,為所有用戶端通路所有站點,或者說大多數站點提供代理。

反向代理:為某一個,或者有限幾個伺服器的前端,為這個伺服器做代理

反向代理實作負載均衡

nginx主要用來做反代,要麼用來做靜态http伺服器。

3.nginx安裝:

3.1編譯安裝:

官網下載下傳源碼包: 依賴元件有: The GNU Compiler Collection The PCRE library The zlib libary OpenSSL 編譯時可以自由加入一些子產品,可以使用./configure --help檢視子產品 編譯指令:(此處編譯過程中自由加入了一些功能,如日志debug等,科根據需求編譯相應的子產品)

./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --user=nginx --group=nginx --error-log-path=/var/nginx/error.log  --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client --with-debug 
           

編譯過程中會有一大堆check

checkingfor OS

 + Linux 3.10.0-229.el7.x86_64 x86_64

checkingfor C compiler ... found

 + using GNU C compiler

 + gcc version: 4.8.5 20150623 (Red Hat4.8.5-11) (GCC)

checkingfor gcc -pipe switch ... found

checkingfor gcc variadic macros ... found

checkingfor C99 variadic macros ... found

checkingfor unistd.h ... found

checkingfor inttypes.h ... found

checkingfor limits.h ... found

checkingfor sys/filio.h ... not found

checkingfor sys/param.h ... found

checkingfor sys/mount.h ... found

checkingfor sys/statvfs.h ... found

checkingfor crypt.h ... found

checkingfor Linux specific features

checkingfor epoll ... found

checkingfor sendfile() ... found

checkingfor sendfile64() ... found

checkingfor sys/prctl.h ... found

checkingfor prctl(PR_SET_DUMPABLE) ... found

checkingfor sched_setaffinity() ... found

checkingfor crypt_r() ... found

checkingfor sys/vfs.h ... found

checkingfor poll() ... found

checkingfor /dev/poll ... not found

checkingfor kqueue ... not found

checkingfor crypt() ... not found

checkingfor crypt() in libcrypt ... found

checkingfor O_DIRECT ... found

checkingfor F_NOCACHE ... not found

checkingfor directio() ... not found

checkingfor statfs() ... found

checkingfor statvfs() ... found

checkingfor dlopen() ... not found

checkingfor dlopen() in libdl ... found

checkingfor sched_yield() ... found

checkingfor PCRE library ... found

checkingfor OpenSSL library ... found

checkingfor zlib library ... found

creatingobjs/Makefile

checkingfor int size ... 4 bytes

checkingfor long size ... 8 bytes

checkingfor long long size ... 8 bytes

checkingfor void * size ... 8 bytes

checkingfor uint64_t ... found

checkingfor sig_atomic_t ... found

checkingfor sig_atomic_t size ... 4 bytes

checkingfor socklen_t ... found

checkingfor in_addr_t ... found

checkingfor in_port_t ... found

checkingfor rlim_t ... found

checkingfor uintptr_t ... uintptr_t found

checkingfor system endianess ... little endianess

checkingfor size_t size ... 8 bytes

checkingfor off_t size ... 8 bytes

checkingfor time_t size ... 8 bytes

checkingfor setproctitle() ... not found

checkingfor pread() ... found

checkingfor pwrite() ... found

checkingfor strerror_r() ... found but is not working

checkingfor gnu style strerror_r() ... found

checkingfor sys_errlist[] ... found

checkingfor localtime_r() ... found

checkingfor posix_memalign() ... found

checkingfor memalign() ... found

checkingfor mmap(MAP_ANON|MAP_SHARED) ... found

checkingfor mmap("/dev/zero", MAP_SHARED) ... found

checkingfor System V shared memory ... found

checkingfor struct msghdr.msg_control ... found

checkingfor ioctl(FIONBIO) ... found

checkingfor struct tm.tm_gmtoff ... found

checkingfor struct dirent.d_namlen ... not found

checkingfor struct dirent.d_type ... found

Configurationsummary

  + using system PCRE library

  + using system OpenSSL library

  + md5: using OpenSSL library

  + sha1 library is not used

  + using system zlib library

  nginx path prefix:"/usr/local/nginx"

  nginx binary file:"/usr/local/nginx/sbin/nginx"

  nginx configuration prefix:"/etc/nginx"

  nginx configuration file:"/etc/nginx/nginx.conf"

  nginx pid file:"/var/run/nginx/nginx.pid"

  nginx error log file:"/var/nginx/error.log"

  nginx http access log file:"/var/log/nginx/access.log"

  nginx http client request body temporaryfiles: "/var/tmp/nginx/client"

  nginx http proxy temporary files:"proxy_temp"

  nginx http fastcgi temporary files:"fastcgi_temp"

編譯完成以後使用指令:

make $$ make install
           

進行配置安裝。 /usr/local/nginx/nginx啟動 ss -tnl:檢視端口

3.2:yum 安裝

配置相關的源,使用指令:yum install nginx -y一鍵安裝即可。

4:nginx的配置檔案: