centos7.4安装配置nginx

一、更新&获取文件

yum update
wget -c https://nginx.org/download/nginx-1.14.2.tar.gz
#解压
tar -zxvf nginx-1.14.2.tar.gz

二、依赖安装

yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

三、编译安装

cd / nginx-1.14.2
./configure
make && make install

四、配置

nano /lib/systemd/system/nginx.service
#将如下红色部分写入文件
[Unit]
Description=nginx
After=network.target
  
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target


#设置开机启动
systemctl enable nginx.service
其余配置在/usr/local/nginx/conf/nginx.conf中进行配置

五、负载均衡配置

在192.150.202.40上
nano /usr/local/nginx/conf/nginx.conf

upstream springboot{
    server 192.150.202.40:8081 weight=20;
    server 192.150.202.41:8081 weight=10;
    //在41上调整权重
}

server{
    listen 8080
    server_name locahost
    ......

    location / {
        proxy_pass http://springboot;
    ......

猜你喜欢

转载自blog.csdn.net/nianqusuifeng/article/details/87971141