Linux安装nginx的步骤

Linux安装nginx的步骤

  1. 更新镜像源
sudo apt-get update
  1. 安装 nginx
sudo apt install nginx -y
  1. 验证 nginx 是否安装成功
http://192.168.192.109

配置 Nginx 反向代理 /etc/nginx/nginx.conf

  • 在 /etc/nginx/conf.d/ 目录下, 新建一个 haredot.conf 文件
server {
   listen 80 ;
   server_name 0.0.0.0 ;
   
   location / {
      proxy_pass http://192.168.192.108:8080 ;
	  include /etc/nginx/proxy_params ;
   }
}
  • 在/etc/nginx$ 目录下 sudo vim nginx.conf 注释这句话
    ·# include /etc/nginx/sites-enabled/*;

  • 验证配置文件是否有语法错误

sudo nginx -t

如果能看到下面的信息就代表 配置文件语法正确
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
  • 重启 nginx 服务器
sudo systemctl restart nginx 

Nginx 负载均衡的配置


upstream www_pools{
   ip_hash ;
   server 192.168.192.107:8080 weight=5;
   server 192.168.192.108:8080; 
} 

server {

   location / {
   
	   proxy_pass http://www_pools ;
	   ...;
   }
}

负载均衡策略有

  • 轮询(默认方式)
  • 权重
  • 随机
  • ip_hash
  • url_hash

猜你喜欢

转载自blog.csdn.net/weixin_52953038/article/details/128365239