随笔 - 63, 文章 - 1, 评论 - 5, 阅读 - 72558
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

centos安装nginx 带upstream

Posted on   追风0315  阅读(2320)  评论(0编辑  收藏  举报

centos安装nginx 带upstream

用途:利用upstream进行socket数据中转
各版本nginx下载地址:http://nginx.org/download/
系统:CentOS 6.5 x64
nginx版本:1.12.1/1.15.10
安装方式:源码编译安装

1.安装必须环境,nginx的编译需要c++,同时prce(重定向支持)和openssl(https支持)也需要安装

yum install gcc-c++
yum -y install pcre*
yum -y install openssl*

2.下载nginx-1.12.1.tar.gz,放在 /usr/local/ 目录下

cd /usr/local/
wget http://nginx.org/download/nginx-1.12.1.tar.gz
tar zxf nginx-1.12.1.tar.gz
cd nginx-1.12.1
./configure --prefix=/usr/local/nginx --with-stream
make && make install

参考:https://www.cnblogs.com/chenjianxiang/p/8489055.html

3.打开防火墙需要允许访问的端口,如端口80,或者直接关闭防火墙

[root@localhost ~]#servcie iptables stop     //临时关闭防火墙
[root@localhost ~]#chkconfig iptables off    //永久关闭防火墙

注:如果提示service not found,下面三种方式解决
a:yum install initscripts -y
b:直接使用su - root来切换到root用户,然后使用 service
c:使用su root切换到root用户,并同时使用/sbin/service来操作,/sbin/service iptables stop

4.nginx.conf配置文件如下

user  nobody;
worker_processes  1;

error_log  logs/error.log;
error_log  logs/error.log  notic/sbine;
error_log  logs/error.log  info;

pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

stream {
    upstream upstream_8002 {
        server us-free.hyss.xyz:48528;  
    }
    server {
        listen 8002;
        listen 8002 udp;
        proxy_pass upstream_8002;
        proxy_timeout 10s;
        proxy_connect_timeout 10s;   
    }

}

5.进入/usr/local/nginx 启动nginx:./nginx

6.如果端口被占用

   查找端口占用
   netstat -lnp|grep xxx xxx请换为你的nginx需要的端口,如:80,会提示进程多少如:1777
   ps 1777 可以看到是哪个路径
   kill -9 1777 //杀掉编号为1777的进程

7.nginx启动报错

   /usr/local/nginx/logs/nginx.pid 路径下找不到nginx.pid
   执行:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

8:centos7 设置开机启动 vim /etc/rc.d/rc.local

增加内容

/usr/local/nginx/sbin/nginx -c /nginx/nginx-1.15.10/conf/nginx.conf

注意 -c 之后的 文件.. 需要确定.

9:centos7关闭防火墙 1、firewalld的基本使用

启动: systemctl start firewalld

关闭: systemctl stop firewalld

查看状态: systemctl status firewalld

开机禁用 : systemctl disable firewalld

开机启用 : systemctl enable firewalld

编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
点击右上角即可分享
微信分享提示