搭建nginx

1.nginx官网下载 tar文件 解压 选择稳定版,各操作系统合理选择

https://nginx.org/en/download.html

2.安装gcc gcc-c++

   yum -y install gcc gcc-++ autoconf atuomake

3.编译 ./configure 

4.如果有PCRE库未安装

 yum -y install pcre pcre-devel

5.如果zlib库没有安装

 yum -y install zlib zlib-devel 

6.make

7.make install

8.测试 cd /usr/local 查看是否有nginx 目录 如果有 安装成功

启动 sbin/bin -c conf 配置文件

 

rpm 包/yum/ apt-get /编辑安装

 

//检查或者下载安装 依赖

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

 

1.如果是tar 包,解压,./configure --prefix=/opt/nginx //目录

2.make && make install 

搭建nginx负载均衡可以按照以下步骤进行: ### 准备工作 安装tomcat,安装完成后,在`./webapps`目录下添加`test`目录,在`test`目录下添加`index.html`文件,并编辑`index.html`文件,例如填写`11111`用于测试 [^3]。 ### 下载Nginx 可以从官网(https://nginx.org/en/download.html/nginx - 1.18.0 )下载Nginx,也可以使用`wget`在线下载。将下载好的`nginx.tar.gz`文件复制到Linux的`/usr/local/`目录下,然后使用`tar -zxvf`命令进行解压 [^3]。 ### 配置Nginx 使用`nginx/nginx.conf`配置文件,示例配置如下: ```plaintext user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; } ``` 此配置文件对Nginx的基本参数、日志格式、网络连接等进行了设置 [^2]。 ### 测试配置 使用命令`nginx -t`来测试Nginx配置文件是否正确。若输出类似`nginx: the configuration file /etc/nginx/nginx.conf syntax is ok`和`nginx: configuration file /etc/nginx/nginx.conf test is successful`的信息,则表示配置文件语法正确且测试成功 [^4]。 ### 启动Nginx 完成上述步骤后,启动Nginx服务,Nginx即可实现负载均衡功能,分担流量,确保高效响应,提升系统的可用性和扩展性,帮助企业应对高并发请求,提升用户体验 [^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值