Centos7 上部署 nginx:nginx 是一个高性能的网页服务器,它能反向代理 HTTP, HTTPS, SMTP, POP3, IMAP 的协议链接,以及一个负载均衡器和一个 HTTP 缓存。这里简单介绍在 Centos7 上部署 nginx。
安装 nginx
使用 root 执行如下命令,将会成功安装 nginx,并设置为开机启动:
- yum install epel-releaseyum install nginxsystemctl start nginxsystemctl enable nginx
我们可以通过如下命令验证 nginx 已经成功运行:
- systemctl status nginx
配置反向代理
配置反向代理的需求:
- 客户端和 nginx 之间通过 https 连接
- nginx 和服务器端之间通过 http 连接
配置过程:
- 证书:准备私钥文件 private-key.pem,自签名的证书文件 self-cert.pem,并复制到 / etc/nginx 目录下,具体参考 Generating a Self?Signed Certificate
- 添加 nginx 配置文件 / etc/nginx/conf.d/tian-3000.conf,具体参考 nginx 反向代理配置文件
- 生效新的配置文件:
- nginx -s reload
问题排查 nginx 作为反向代理时,不能连接到服务器,并报错 (13: Permission denied) while connecting to upstream
问题描述:nginx 作为反向代理时,不能连接到服务器,报错类似:
2017/03/31 14:52:15 [crit] 14406#0: *44 connect() to 172.16.3.171:3000 failed (13: Permission denied) while connecting to upstream, client: 172.16.0.234, server: _, request: "GET / HTTP/1.1", upstream: "http://172.16.3.171:3000/", host: "172.16.0.234"
问题原因:SELinux 禁止 nginx 访问 Server
问题解决:修改配置文件 / etc/selinux/config,将 SELINUX 设置为 disabled,重新启动机器
文件句柄不够用
问题描述:nginx 是高性能服务器,有可能需要使用大量的文件句柄
问题解决:修改配置文件 / etc/systemd/system/multi-user.target.wants/nginx.service,在 Service 节中添加: LimitNOFILE=655350
如下命令使得配置生效:
- systemctl daemon-reloadsystemctl restart nginx
就爱阅读 www.92to.com 网友整理上传, 为您提供最全的知识大全, 期待您的分享,转载请注明出处。
来源: http://www.92to.com/bangong/2017/04-01/19791176.html