CentOS 7 Nginx安装配置
1、添加Nginx源
yum install epel-release
2、安装Nginx
yum install nginx
3、启动Nginx
systemctl start nginx //配置Firewall
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
常用操作:
//启动
systemctl start nginx
//停止
systemctl stop nginx
//重启
systemctl restart nginx
//查看运行状态
systemctl status nginx
开机启动
systemctl enable nginx
4、配置Nginx
//打开配置文件
vim /etc/nginx/nginx.conf //配置节点 地址结尾最好加上‘/’
location / {
proxy_pass http://localhost:5000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
} //保存退出
:wq //重启Nginx
systemctl restart nginx
负载配置
upstream webapp {
ip_hash;
server 127.0.0.1:8006 weight=10;
server 127.0.0.1:8007 down;
server 127.0.0.1:8006 max_fails=3 fail_timeout=30s;
server 127.0.0.1:8007 backup;
}
location / {
proxy_pass http://webapp/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
}
说明:
upstream分为以下几种:
1、轮询(默认)
每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除。
2、weight
指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。
2、ip_hash
每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。
3、fair(第三方)
按后端服务器的响应时间来分配请求,响应时间短的优先分配。
4、url_hash(第三方)
按访问url的hash结果来分配请求,使每个url定向到同一个后端服务器,后端服务器为缓存时比较有效。
参数:
down 表示负载过重或者不参与负载
weight 权重过大代表承担的负载就越大
backup 其它服务器时或down时才会请求backup服务器
max_fails 失败超过指定次数会暂停或请求转往其它服务器
fail_timeout 失败超过指定次数后暂停时间
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
两者区别:
X-Forwarded-For是用于记录代理信息的,每经过一级代理(匿名代理除外),代理服务器都会把这次请求的来源IP追加在X-Forwarded-For中,如: X-Forwarded-For: 1.1.1.1, 2.2.2.2, 3.3.3.3 代表 请求由1.1.1.1发出,经过第一层2.2.2.2 转发,第二层是3.3.3.3 转发,而X-Real-IP,一般只记录真实发出请求的客户端IP,如果配置了X-Read-IP,将会是 X-Real-IP: 1.1.1.1 ,如果只有一层代理,这两个头的值一样。
文章出处:http://www.cnblogs.com/anech/p/6866368.html
CentOS 7 Nginx安装配置的更多相关文章
- CentOS系统Nginx安装配置,随时更新
./configure --prefix=/etc/nginx \ #指定安装目录 --sbin-path=/usr/sbin/nginx \ #指定执行路径--conf-path=/etc/ngin ...
- CentOS 6.5安装配置LNMP服务器(Nginx+PHP+MySQL)
CentOS 6.5安装配置LNMP服务器(Nginx+PHP+MySQL) 一.准备篇: /etc/init.d/iptables stop #关闭防火墙 关闭SELINUX vi /etc/sel ...
- CentOS 7.0安装配置Vsftp服务器
一.配置防火墙,开启FTP服务器需要的端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop fi ...
- Nginx安装配置(转)
Nginx 安装配置 Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/ ...
- CentOS 7.0安装配置Vsftp服务器步骤详解
安装Vsftp讲过最多的就是在centos6.x版本中了,这里小编看到有朋友写了一篇非常不错的CentOS 7.0安装配置Vsftp服务器教程,下面整理分享给各位. 一.配置防火墙,开启FTP服务器需 ...
- centos tomcat/resin安装配置 卸载系统自带的java tomcat安装配置 安装JDK resin安装配置 第二十八节课
centos tomcat/resin安装配置 卸载系统自带的java tomcat安装配置 安装JDK resin安装配置 第二十八节课 tomcat和java都不需要编译 tom ...
- Hearbeat + Nginx 安装配置
Hearbeat + Nginx 安装配置 实验环境 两台主机:Linux Centos 6.5 32位 主 服务端:Hearbeat + Nginx eth0:192.168.1.160(公网) e ...
- 【转发】【linux】【ftp】CentOS 7.0安装配置Vsftp服务器
adduser -d /var/www/android -g ftp -s /sbin/nologin ftp2 一.配置防火墙,开启FTP服务器需要的端口 CentOS 7.0默认使用的是firew ...
- CentOS 7.2安装配置Vsftp服务器
一.配置防火墙,开启FTP服务器需要的端口 CentOS 7.2默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop fi ...
随机推荐
- timeline css
CODE <!doctype html> <html> <head> <meta charset="UTF-8"> <titl ...
- Google发布机器学习术语表 (包括简体中文)
Google 工程教育团队已经发布了多语种的 Google 机器学习术语表,该术语表中列出了一般的机器学习术语和 TensorFlow 专用术语的定义.语言版本包括西班牙语,法语,韩语和简体中文. 查 ...
- LeetCode_Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number. The ...
- SKBUFFER详解
纯属转载,不敢侵犯别人产权!! 一. SKB_BUFF的基本概念1. 一个完整的skb buff组成(1) struct sk_buff--用于维护socket buffer状态和描述信息(2) he ...
- windows系统的对象管理
windows中的对象和高级编程语言中所说的对象还欧区别,准确来讲,windows中的对象其实指的是一种数据结构并且是一种带着“对象头(object head)” 的数据结构! 所以windows中 ...
- 爬虫之cookiejar模块
简介 有时候我们需要爬一些需要登录才能进入网页,这个时候就要用到cookie相关的一些模块来操作了 内置的http包里包含了cookie相关的一些模块,通过她们我们可以自动使用cookie Cooki ...
- understand EntityManager.joinTransaction()
Join Transaction The EntityManager.joinTransaction() API allows an application managed EntityManager ...
- 服务遇到错误。很可能由IncludeExceptionDetailInFaults=true创建的ExceptionDetail,其值为:System.ArgumentException:指定的值还有无效的控制字符
解决方案:将服务的应用程序池由 集成 修改为 经典.(或者 可以反过来试下.) 环境:WindowsServer2008R2+IIS7.5+WCF 出错样图:
- 16.遇到就jar mismatch! Fix your dependencies的问题
这是因为两个项目的jar包(android-support-v4.jar)不一致. 解决方法是把2个jar都删除,然后各自加上最新的jar包 但是换了之后发现R文件编不出来,原因是minsdk的设置问 ...
- jetBrains设置appium环境