当前位置: 首页 > news >正文

在开启 selinux 和配置防火墙的情况下安装和使用 nginx

添加 nginx 仓库配置文件

sudo vi /etc/yum.repos.d/nginx.repo

添加内容:

nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1

其中 OS 替换成 rhel 或者 centos, OSRELEASE 替换成 6 或者 7. 例如:

nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

安装

sudo yum clean all
sudo yum makecache

查看 nginx 有那些可以安装

sudo yum provides nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile* base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
1:nginx-1.8.0-1.el7.ngx.x86_64 : High performance web server
Repo        : nginx1:nginx-1.8.1-1.el7.ngx.x86_64 : High performance web server
Repo        : nginx1:nginx-1.10.0-1.el7.ngx.x86_64 : High performance web server
Repo        : nginx1:nginx-1.10.1-1.el7.ngx.x86_64 : High performance web server
Repo        : nginx1:nginx-1.10.2-1.el7.ngx.x86_64 : High performance web server
Repo        : nginx1:nginx-1.10.3-1.el7.ngx.x86_64 : High performance web server
Repo        : nginx1:nginx-1.12.0-1.el7.ngx.x86_64 : High performance web server
Repo        : nginx1:nginx-1.12.1-1.el7.ngx.x86_64 : High performance web server
Repo        : nginx1:nginx-1.12.2-1.el7_4.ngx.x86_64 : High performance web server
Repo        : nginx

安装最新的稳定版:

sudo yum install nginx-1.12.2-1.el7_4.ngx.x86_64 -y

设置开机启动

sudo systemctl daemon-reloadsudo systemctl enable nginx

系统调优

CentOS 7 系统调优

配置 nginx

查看 /etc/nginx/nginx.conf

user  nginx;
worker_processes  1;error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;events {worker_connections  1024;
}http {include       /etc/nginx/mime.types;default_type  application/octet-stream;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  /var/log/nginx/access.log  main;sendfile        on;#tcp_nopush     on;keepalive_timeout  65;#gzip  on;include /etc/nginx/conf.d/*.conf;
}
user : nginx 启动的用户, 如果是静态资源,需要该用户有权限访问才可以.
worker_processes: 子进程数

待续。。。

开放端口

sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
sudo firewall-cmd --reloadsudo firewall-cmd --list-ports

如果出现 403 的错误

如果开启了 selinux, 就首先排除 selinux 导致的错误,
先把 selinux 设置为 disabled, 如果依然有问题,查看防火墙是否添加了端口,如果添加了,
检查 nginx 是配置有问题。 如果一切正常, 那么考虑是 selinux 导致的错误, 再次开启 selinux,
如果还有错,就参考下面的解决方法:

sudo yum install setroubleshoot
sudo sealert -a /var/log/audit/audit.log

根据日志对应的处理, 如果还解决不了, 继续

sudo cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -m nginxlocalconf

如果有 httpd_t 的问题, 执行:

sudo semanage permissive -a httpd_t

继续:

sudo ausearch -c 'nginx' --raw | audit2allow -M my-nginx

根据提示处理…

参考:

Using Apache and SELinux Together

Nginx proxy_pass not working in selinux

centos 7 上配置SELinux允许nginx指定/home/www作为网站根目录

相关文章:

  • 基于tomcat运行jenkins常见的报错处理
  • 配置Jenkins自动构建打包项目
  • vue3+threejs+koa可视化项目——模型文件上传(第四步)
  • 已解决org.aopalliance.aop.AspectException异常的正确解决方法,亲测有效!!!
  • 【OpenHarmony硬件操作】WIFI模块的操作(udp+tcp)
  • 深入解析torch.load中的【map_location】参数
  • 安全基础~通用漏洞4
  • Flink流式数据倾斜
  • 案例:爬取豆瓣电影 Top250 的数据
  • VBA技术资料MF117:测试显示器大小
  • 深度学习自然语言处理(NLP)模型BERT:从理论到Pytorch实战
  • 设计模式1-访问者模式
  • Linux 命令行速查表
  • Android 11 访问 Android/data/或者getExternalCacheDir() 非root方式
  • vim常用命令以及配置文件
  • 《Java8实战》-第四章读书笔记(引入流Stream)
  • centos安装java运行环境jdk+tomcat
  • CSS 三角实现
  • eclipse的离线汉化
  • Golang-长连接-状态推送
  • JavaScript标准库系列——Math对象和Date对象(二)
  • mockjs让前端开发独立于后端
  • PermissionScope Swift4 兼容问题
  • Python代码面试必读 - Data Structures and Algorithms in Python
  • Sass 快速入门教程
  • scrapy学习之路4(itemloder的使用)
  • Shell编程
  • Vue ES6 Jade Scss Webpack Gulp
  • vue总结
  • - 概述 - 《设计模式(极简c++版)》
  • 普通函数和构造函数的区别
  • 强力优化Rancher k8s中国区的使用体验
  • 使用 Node.js 的 nodemailer 模块发送邮件(支持 QQ、163 等、支持附件)
  • 使用parted解决大于2T的磁盘分区
  • 硬币翻转问题,区间操作
  • RDS-Mysql 物理备份恢复到本地数据库上
  • ​2021半年盘点,不想你错过的重磅新书
  • ​业务双活的数据切换思路设计(下)
  • #我与Java虚拟机的故事#连载09:面试大厂逃不过的JVM
  • %3cscript放入php,跟bWAPP学WEB安全(PHP代码)--XSS跨站脚本攻击
  • (3)选择元素——(14)接触DOM元素(Accessing DOM elements)
  • (html转换)StringEscapeUtils类的转义与反转义方法
  • (JS基础)String 类型
  • (TipsTricks)用客户端模板精简JavaScript代码
  • (附源码)springboot家庭财务分析系统 毕业设计641323
  • (附源码)springboot建达集团公司平台 毕业设计 141538
  • (正则)提取页面里的img标签
  • (转)Oracle 9i 数据库设计指引全集(1)
  • (转)母版页和相对路径
  • (轉貼) 2008 Altera 亞洲創新大賽 台灣學生成果傲視全球 [照片花絮] (SOC) (News)
  • .NET Framework与.NET Framework SDK有什么不同?
  • .NET框架设计—常被忽视的C#设计技巧
  • .NET中的Exception处理(C#)
  • /bin/rm: 参数列表过长"的解决办法
  • [22]. 括号生成