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网站用户有:百度、京东、新浪、网易、腾讯、淘宝等。
主要作用: 轻量级的Web 服务器和反向代理服务器
一、软件安装
yum安装
1.先安装epel-release扩展包
2.在安装nginx服务
yum install nginx
3.修改配置文件
vim /etc/nginx/nginx.conf
1 #用户是nginx 2 user nginx; 3 #工作进程自动(有多少cpu就开多少进程) 4 worker_processes auto; 5 #错误日志 6 error_log /var/log/nginx/error.log; 7 8 9 pid /run/nginx.pid; 10 11 # Load dynamic modules. See /usr/share/nginx/README.dynamic. 12 include /usr/share/nginx/modules/*.conf; 13 14 events { 15 #一个进程里边开多少个线程 16 worker_connections 1024; 17 } 18 19 http { 20 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 21 '$status $body_bytes_sent "$http_referer" ' 22 '"$http_user_agent" "$http_x_forwarded_for"'; 23 #访问日志 24 access_log /var/log/nginx/access.log main; 25 26 sendfile on; 27 tcp_nopush on; 28 tcp_nodelay on; 29 keepalive_timeout 65; 30 types_hash_max_size 2048; 31 32 include /etc/nginx/mime.types; 33 default_type application/octet-stream; 34 35 # Load modular configuration files from the /etc/nginx/conf.d directory. 36 # See http://nginx.org/en/docs/ngx_core_module.html#include 37 # for more information. 38 # 可自定义的配置文件 39 include /etc/nginx/conf.d/*.conf; 40 41 server { 42 #监听的端口号 43 listen 80 default_server; 44 listen [::]:80 default_server; 45 server_name _; 46 #网站的根目录 47 root /usr/share/nginx/html; 48 49 # Load configuration files for the default server block. 50 include /etc/nginx/default.d/*.conf; 51 52 location / { 53 } 54 55 error_page 404 /404.html; 56 location = /40x.html { 57 } 58 59 error_page 500 502 503 504 /50x.html; 60 location = /50x.html { 61 } 62 }