新聞中心
一、 Nginx 簡(jiǎn)介

Nginx 是由俄羅斯軟件工程師 Igor Sysoev 開發(fā)的一個(gè)高性能的 http 和反向代理服務(wù)器,具備 IMAP/POP3 和 SMTP 服務(wù)器功能。
作為 Web 服務(wù)器:相比較與 Apache, Nginx 使用更少的資源,支持更多的并發(fā)連接,體現(xiàn)更高的效率,這點(diǎn)使 Nginx 尤為受到虛擬主機(jī)提供商的歡迎,能夠支持高達(dá) 50000 個(gè)并發(fā)的連接數(shù)的響應(yīng)。
作為負(fù)載均衡服務(wù)器: Nginx 既可以在內(nèi)部直接支持 Rails 和 PHP,也可以支持作為 HTTP代理服務(wù)器對(duì)外驚醒服務(wù), Nginx 用 C 語言編寫,不論是系統(tǒng)資源開銷還是 CPU 使用效率都比 Perlbal 要好的多。
作為郵件代理服務(wù)器: Nginx 同時(shí)也是一個(gè)非常優(yōu)秀的郵件代理服務(wù)器。(最早開發(fā)這個(gè)產(chǎn)品的目的之一也是作為郵件代理服務(wù)器)
二、centos 7下安裝部署
配置epel yum 源
wget http://dl.Fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ivh epel-release-latest-7.noarch.rpm
yum install nginx -y
查看確認(rèn) 是否安裝
[root@localhost ~]# rpm -qa | grep nginx
nginx-1.10.2-1.el7.x86_64
nginx-mod-stream-1.10.2-1.el7.x86_64
nginx-mod-http-geoip-1.10.2-1.el7.x86_64
nginx-all-modules-1.10.2-1.el7.noarch
nginx-mod-http-perl-1.10.2-1.el7.x86_64
nginx-mod-http-image-filter-1.10.2-1.el7.x86_64
nginx-mod-mail-1.10.2-1.el7.x86_64
nginx-filesystem-1.10.2-1.el7.noarch
nginx-mod-http-xslt-filter-1.10.2-1.el7.x86_64
查看 安裝nginx 所生成的文件
[root@localhost ~]# rpm -ql nginx
/etc/logrotate.d/nginx
/etc/nginx/fastcgi.conf
/etc/nginx/fastcgi.conf.default
/etc/nginx/fastcgi_params
/etc/nginx/fastcgi_params.default
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/mime.types.default
/etc/nginx/nginx.conf
/etc/nginx/nginx.conf.default
/etc/nginx/scgi_params
/etc/nginx/scgi_params.default
/etc/nginx/uwsgi_params
/etc/nginx/uwsgi_params.default
/etc/nginx/win-utf
/usr/bin/nginx-upgrade
/usr/lib/systemd/system/nginx.service
/usr/lib64/nginx/modules
/usr/sbin/nginx
/usr/share/doc/nginx-1.10.2
/usr/share/doc/nginx-1.10.2/CHANGES
/usr/share/doc/nginx-1.10.2/README
/usr/share/doc/nginx-1.10.2/README.dynamic
/usr/share/doc/nginx-1.10.2/UPGRADE-NOTES-1.6-to-1.10
/usr/share/licenses/nginx-1.10.2
/usr/share/licenses/nginx-1.10.2/LICENSE
/usr/share/man/man3/nginx.3pm.gz
/usr/share/man/man8/nginx-upgrade.8.gz
/usr/share/man/man8/nginx.8.gz
/usr/share/nginx/html/404.html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/usr/share/nginx/html/nginx-logo.png
/usr/share/nginx/html/poweredby.png
/usr/share/vim/vimfiles/ftdetect/nginx.vim
/usr/share/vim/vimfiles/indent/nginx.vim
/usr/share/vim/vimfiles/syntax/nginx.vim
/var/lib/nginx
/var/lib/nginx/tmp
/var/log/nginx
三、測(cè)試nginx
啟動(dòng)nginx
systemctl start nginx
設(shè)置開機(jī)啟動(dòng)
systemctl enable nginx
查看nginx 啟動(dòng)狀態(tài)
systemctl status nginx
查看是否監(jiān)聽
ss -tnl | grep 80
LISTEN 0 128 *:80 *:*
LISTEN 0 128 :::80 :::*
測(cè)試 nginx
在瀏覽器中輸入 nginx 服務(wù)器的ip 地址
備注:如果不能正常訪問,關(guān)閉防火墻
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機(jī)啟動(dòng)
firewall-cmd --state #查看默認(rèn)防火墻狀態(tài)(關(guān)閉后顯示notrunning,開啟后顯示running)
測(cè)試頁面
安裝成功
四、nginx 的配置文件說明
配置文件路徑 /etc/nginx/nginx.conf
#運(yùn)行用戶
user nginx;
#啟動(dòng)進(jìn)程,通常設(shè)置成和 cpu 的數(shù)量相等
worker_processes 1;
#全局錯(cuò)誤日志及 PID 文件
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
#工作模式及連接數(shù)上限
events {
#epoll 是多路復(fù)用 IO(I/O Multiplexing)中的一種方式,
#僅用于 linux2.6 以上內(nèi)核,可以大大提高 nginx 的性能
use epoll;
#單個(gè)后臺(tái) worker process 進(jìn)程的最大并發(fā)鏈接數(shù)
worker_connections 1024;
# 并發(fā)總數(shù)是 worker_processes 和 worker_connections 的乘積
# 即 max_clients = worker_processes * worker_connections
# 在設(shè)置了反向代理的情況下, max_clients = worker_processes * worker_connections / 4
為什么
# 為什么上面反向代理要除以 4,應(yīng)該說是一個(gè)經(jīng)驗(yàn)值
# 根據(jù)以上條件,正常情況下的 Nginx Server 可以應(yīng)付的最大連接數(shù)為: 4 * 8000 = 32000
# worker_connections 值的設(shè)置跟物理內(nèi)存大小有關(guān)
# 因?yàn)椴l(fā)受 IO 約束, max_clients 的值須小于系統(tǒng)可以打開的最大文件數(shù)
# 而系統(tǒng)可以打開的最大文件數(shù)和內(nèi)存大小成正比,一般 1GB 內(nèi)存的機(jī)器上可以打開的文件數(shù)大約是
10 萬左右
# 我們來看看 360M 內(nèi)存的 VPS 可以打開的文件句柄數(shù)是多少:
# $ cat /proc/sys/fs/file-max
# 輸出 34336
# 32000 < 34336,即并發(fā)連接總數(shù)小于系統(tǒng)可以打開的文件句柄總數(shù),這樣就在操作系統(tǒng)可以承受
的范圍之內(nèi)
# 所以, worker_connections 的值需根據(jù) worker_processes 進(jìn)程數(shù)目和系統(tǒng)可以打開的最大文
件總數(shù)進(jìn)行適當(dāng)?shù)剡M(jìn)行設(shè)置
# 使得并發(fā)總數(shù)小于操作系統(tǒng)可以打開的最大文件數(shù)目
# 其實(shí)質(zhì)也就是根據(jù)主機(jī)的物理 CPU 和內(nèi)存進(jìn)行配置
# 當(dāng)然,理論上的并發(fā)總數(shù)可能會(huì)和實(shí)際有所偏差,因?yàn)橹鳈C(jī)還有其他的工作進(jìn)程需要消耗系統(tǒng)資源。
# ulimit -SHn 65535
}
http {
#設(shè)定 mime 類型,類型由 mime.type 文件定義
include mime.types;
default_type application/octet-stream;
#設(shè)定日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
#sendfile 指令指定 nginx 是否調(diào)用 sendfile 函數(shù)( zero copy 方式)來輸出文件,
#對(duì)于普通應(yīng)用,必須設(shè)為 on,
#如果用來進(jìn)行下載等應(yīng)用磁盤 IO 重負(fù)載應(yīng)用,可設(shè)置為 off,
#以平衡磁盤與網(wǎng)絡(luò) I/O 處理速度,降低系統(tǒng)的 uptime.
sendfile on;
#tcp_nopush on;
#連接超時(shí)時(shí)間
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
#開啟 gzip 壓縮
gzip on;
gzip_disable "MSIE [1-6].";
#nginx 傳輸文件大小,默認(rèn)為1M
client_max_body_size 20m;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
#設(shè)定請(qǐng)求緩沖
client_header_buffer_size 128k;
large_client_header_buffers 4 128k;
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} #
禁止訪問 .htxxx 文件
location ~ /.ht {
deny all;
}
}
}
網(wǎng)站名稱:CentOS7下Nginx服務(wù)器的安裝配置
當(dāng)前地址:http://m.fisionsoft.com.cn/article/dhcdhpp.html


咨詢
建站咨詢
