CentOS 7下Nginx服务器的安装配置

Nginx 是由俄罗斯软件工程师 Igor Sysoev 开发的一个高性能的 HTTP 和反向代理服务器,具备 IMAP/POP3 和 SMTP 服务器功能。

作为 Web 服务器:相比较与 Apache, Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率,这点使 Nginx 尤为受到虚拟主机提供商的欢迎,能够支持高达 50000 个并发的连接数的响应。

作为负载均衡服务器: Nginx 既可以在内部直接支持 Rails 和 PHP,也可以支持作为 HTTP代理服务器对外惊醒服务, Nginx 用 C 语言编写,不论是系统资源开销还是 CPU 使用效率都比 Perlbal 要好的多。

作为邮件代理服务器: Nginx 同时也是一个非常优秀的邮件代理服务器。(最早开发这个产品的目的之一也是作为邮件代理服务器)

二、CentOS 7下安装部署
配置epel yum 源
wget Fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ivh epel-release-latest-7.noarch.rpm
yum install nginx -y


查看确认 是否安装
[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


三、测试nginx
启动nginx 
systemctl start nginx


设置开机启动
systemctl enable nginx


查看nginx 启动状态
systemctl status nginx


查看是否监听


 ss -tnl | grep 80
LISTEN    0      128          *:80                      *:*                 
LISTEN    0      128        :::80                      :::* 


测试 nginx


在浏览器中输入 nginx 服务器的ip 地址
备注:如果不能正常访问,关闭防火墙
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

测试页面

安装成功

四、nginx 的配置文件说明

配置文件路径  /etc/nginx/nginx.conf

#运行用户
user nginx;
#启动进程,通常设置成和 cpu 的数量相等
worker_processes 1;
#全局错误日志及 PID 文件
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
#工作模式及连接数上限
events {
#epoll 是多路复用 IO(I/O Multiplexing)中的一种方式,
#仅用于 linux2.6 以上内核,可以大大提高 nginx 的性能
use epoll;
#单个后台 worker process 进程的最大并发链接数
worker_connections 1024;
# 并发总数是 worker_processes 和 worker_connections 的乘积
# 即 max_clients = worker_processes * worker_connections
# 在设置了反向代理的情况下, max_clients = worker_processes * worker_connections / 4

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/2063e5d73232e15d79a613654848ad74.html