yum 安装有个缺点,无法安装插件

1、添加源


  1. rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2、安装Nginx


yum install -y nginx

3、启动Nginx并设置开机自动运行


systemctl start nginx.service
systemctl enable nginx.service

4、查看安装位置和配置文件


whereis nginx

默认配置文件位置 /etc/nginx/conf.d 有个default.conf

5、查看


#访问
hppt://ip:80

6、简单配置


配置官网

server {
    listen       80;
    server_name  zy.ciicsys.com;  #通过域名可以访问 /home/humanImgs/dist目录下的静态文件

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /home/humanImgs/dist;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
}

7、配置负载均衡


# 增加一个负载均衡节点
  upstream www.alan.hsiang.com {
       server 192.168.127.132:8080 weight=1;
       server 192.168.127.132:8081 weight=2;
       ip_hash;
 }


#新增一个服务节点
    server {
       listen 80;
       server_name wwww.alan.hsiang.com;
       location / {
          #root html3;
          #index index.html index.html;
          proxy_pass http://www.alan.hsiang.com;
       }
    }

配置负载均衡,除了weight外,还有其他一些参数,如下所示:

  1. down,表示当前的server暂时不参与负载均衡。
  2. backup,预留的备份机器。当其他所有的非backup机器出现故障或者忙的时候,才会请求backup机器,因此这台机器的压力最轻。
  3. max_fails,允许请求失败的次数,默认为1。当超过最大次数时,返回proxy_next_upstream 模块定义的错误。
  4. fail_timeout,在经历了max_fails次失败后,暂停服务的时间。max_fails可以和fail_timeout一起使用。