美文网首页nginx
nginx 安装和基本配置

nginx 安装和基本配置

作者: 待汝豪杰只是凡夫 | 来源:发表于2017-06-15 00:55 被阅读0次

contos 7
下载
<pre>
wget http://nginx.org/download/nginx-1.12.0.tar.gz
</pre>
解压
<pre>
tar -zxvf nginx-1.12.0.tar.gz
</pre>
编译安装
首先:
<pre>
./configure
</pre>
安装的时候报错处理
安装 gcc& gc++:
<pre>
yum -y install gcc gcc-c++ autoconf automake
</pre>
安装 pcre:
<pre>
yum -y install pcre pcre-devel
</pre>
安装 zlib: ​
<pre>
yum -y install zlib zlib-devel
</pre>
其次:
<pre>
make
</pre>
然后:
<pre>
make install​
</pre>
启动Nginx命令:
<pre>
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
</pre>
简单配置
1.首先我的服务器上跑了2个tomcat
一个跑在8080端口,一个跑在8089端口,2个index.html略不同
2.备份 nginx.conf 文件为新文件 nginx.conf.base​ (防止修改出错无法还原)命令​:
<pre>
cp/usr/local/nginx/conf/nginx.conf/usr/local/nginx/conf/nginx.conf.base
</pre>
3.​修改nginx.conf
​在http节点下添加upstream节点
a.配置1:按照请求到达时序按权重进行负载均衡(如下:8080端口的服务收到请求数量是8089的两倍)
<pre>
upstream mayanyu{
server 127.0.0.1:8080 weight=2;
server 127.0.0.1:8089 weight=1;
}
</pre>
b.配置2,按照IP进行负载均衡(可以解决session共享问题)
<pre>
upstream mayanyu{
ip_hash;
server 127.0.0.1:8080;
server 127.0.0.1:8089;
}
</pre>
在server下的location下添加一行:
<pre>
proxy_pass http://mayanyu;​
</pre>
测试配置文件并启动或者重启Nginx
测试​配置文件:
<pre>
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
</pre>
<pre>
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
</pre>
启动:
<pre>
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
</pre>
重启:
<pre>
/usr/local/nginx/sbin/nginx -s reload
</pre>
访问你的服务器80端口:http://ip:80
刷新之后显示的页面不同,说明负载均衡成功了(我服务器上的2个tomcat的index.html不同)​

相关文章

  • 一.CentOS7手动部署WordPress网站

    前提: 开始安装LNMP基本环境: 1.安装及配置nginx 安装: 配置: 1.运行以下命令备份Nginx配置文...

  • nginx 安装和基本配置

    contos 7下载 wget http://nginx.org/download/nginx-1.12.0.ta...

  • [Nginx]01 - 安装以及基本配置

    目录 Nginx基础概念 安装Nginx与基本命令 配置nginx 初次使用nginx 1. Nginx基础概念 ...

  • nginx知识介绍

    1.nginx基本介绍 2.nginx是什么,可以干什么 3.nginx 安装,常用命令和配置文件 4.nginx...

  • nginx实现简单的代理任务

    简单的写了下mac下的nginx的安装和配置 一、nginx的安装二、nginx的配置 熟悉nginx目录 ngi...

  • 2019-01-18

    nginx的基本配置和SSL的http跳转https基本配置 在nginx中的nginx.conf下配置 http...

  • nginx本地配置web项目-layui

    nginx安装配置以及配置本地web项目 nginx下载和安装介绍 nginx(engine x) 是一个高性能的...

  • nginx学习目录

    nginx安装部署和配置管理 nginx日志配置 nginx平滑升级与回滚 nginx反向代理 nginx负载均衡...

  • 安装web服务器nginx

    安装nginx 服务器和php7 首先需要安装需要安装 nginx 接下来我们来配置nginx,首先打开配置文件,...

  • Mac系统下nginx的安装

    简单的写了下mac下的nginx的安装和配置 一、nginx的安装二、nginx的配置 确认你的电脑是否安装hom...

网友评论

    本文标题:nginx 安装和基本配置

    本文链接:https://www.haomeiwen.com/subject/msxyqxtx.html