Nginx单机环境搭建及配置

xiaoxiao2021-02-28  37

简介

Nginx是一个web服务器也可以用来做负载均衡及反向代理使用,目前使用最多的就是负载均衡,详细见百度

第一步:下载

下载地址:http://nginx.org/en/download.html,我选择的版本是nginx-1.10.3(如果版本不一致可能存在差异)。

下载下来压缩包为nginx-1.10.3.tar.gz。请使用tar -xzvf nginx-1.10.3.tar.gz解压

第二步:安装

进入Nginx解压目录,执行以下命令安装: ./configure && make && make install

默认安装目录为:/usr/local/nginx

第三步:配置

为了使得配置的server更加清晰,此处将每一个server单独剥离出来,场景如下:

有两台应用服务器,IP+PORT分别为:10.100.96.142:8080和10.100.96.143:8080,需配置轮询负载均衡

在/usr/local/nginx/conf下创建vhost目录,新建8080.xml(名字随意)文件

8080.xml配置如下:

server { listen 80; server_name 8080; #access_log logs/host.access.log main; location /ssm { root html; 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 html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 location ~ .*$ { proxy_pass http://8080; } }

配置/usr/local/nginx目录下的nginx.xml(注意upstream的配置,有需要可以加权重weight):

#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; upstream 8080 { server 10.100.96.142:8080; server 10.100.96.143:8080; } include vhost/*.conf; }

第四步:启动Nginx

启动前检查,如果配置错误会提示./sbin/nginx -t重启Nginx服务 查找当前nginx进程号,然后输入命令: ./sbin/nginx -s reload或kill -HUP 进程号 实现重启nginx服务 启动完成后,输入Nginx地址,如下即为成功

转载请注明原文地址: https://www.6miu.com/read-2624030.html

最新回复(0)