CentOS安装nginx


常规安装

CentOS只需要一条指令就能安装好nginx

前提是已经配置好了yum的镜像,如果没有配置,参考:CentOS配置阿里云镜像-YES开发框架网

Markup 全选
yum install -y nginx

安装后,在目录 /etc/nginx 中可进行nginx的配置

使用Stream模块

如果要使用stream模块,使用如下命令安装

Markup 全选
yum install -y nginx nginx-mod-stream

参考:Centos 利用yum源安装 nginx stream模块_nginx centos7安装 stream-CSDN博客

 

如果yum源安装提示nginx包不存在,就用官方源安装

/etc/yum.repos.d目录添加 nginx.repo文件,文件内容如下

Markup 全选
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

然后再执行 yum install -y nginx 安装即可

 

安装后,启动以及设置开机启动nginx

Markup 全选
# 启动nginx
systemctl start nginx

# 设置开机启动
systemctl enable nginx

 

端口转发报错

端口转发配置:

Markup 全选
server {
  listen 8080;

  gzip on;
  gzip_buffers 32 4K;
  gzip_comp_level 6;
  gzip_min_length 100;
  gzip_proxied any;
  gzip_types application/json text/plain text/xml text/css;
  gzip_vary on;
  gzip_http_version   1.0;
  gzip_disable "MSIE [1-6]\.(?!.*SV1)";

  # 设置上传文件的大小
  client_max_body_size 100m;
  
  location / {
    proxy_pass http://127.0.0.1:18090;
  }
}

转发本地端口报错:

2025/07/01 09:19:35 [crit] 23051#23051: *75 connect() to 127.0.0.1:18090 failed (13: Permission denied) while connecting to upstream, client: 192.168.110.178, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:18090/favicon.ico", host: "192.168.10.101:8080", referrer: "http://192.168.10.101:8080/open-ui5/last/index.html"

解决办法

执行命令:

Markup 全选
setsebool -P httpd_can_network_connect 1

然后重启或者重载

Markup 全选
# 停止
systemctl restart nginx

# 重载
nginx -s reload

 

 

版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
张国生
上一篇:测试机docker-compose.yml
下一篇:宝塔系统 nginx位置记录
评论列表

发表评论

评论内容
昵称:
关联文章

CentOS安装nginx
CentOS安装宝塔
CentOS7安装Docker
CentOS7 nginx SSL证书申请并自动续期
nginx安装为windows服务
CentOS安装java
CentOS Docker中安装gitlab
Nginx部署
windows下openssl安装,证书生成,nginx配置https以及http重定向https
nginx初始配置优化
nginx反向代理https
宝塔系统 nginx位置记录
CentOS Docker中安装gitea
windows Nginx配置开机自启动
CentOS 7 安装 docker compose 教程
CentOS7部署OpenVPN服务端
nginx端口转发配置
CentOS 磁盘扩容
CentOS安装squid代理。用于代理转发微信,钉钉接口。解决IP白名单问题
LInux Jenkins安装

联系我们
联系电话:15090125178(微信同号)
电子邮箱:garson_zhang@163.com
站长微信二维码
微信二维码