NGINX 安装于配置
just a simple example, for more information -> http://nginx.org/en/docs/.
1.vi /etc/yum.repos.d/nginx.repo
2. find repo from http://nginx.org/packages, choose version according to your system. save it.
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/[OS(for example:centos)]/$releasever/$basearch/
gpgcheck=0
enabled=1
3.yum install nginx
4.config nginx
u can edit nginx.conf directly or use "include" in nginx.conf
(1)root
A location context can contain directives that define how to resolve a request
¨C either serve a static file or pass the request to a proxied server.
(2)proxy_pass
The proxy_pass directive passes the request to the proxied server accessed with the configured URL.
The response from the proxied server is then passed back to the client.
(3)proxy_set_header (NGINX Reverse Proxy)
By default, NGINX redefines two header fields in proxied requests, ¡°Host¡± and ¡°Connection¡±,
and eliminates the header fields whose values are empty strings. ¡°Host¡± is set to the $proxy_host variable,
and ¡°Connection¡± is set to close:
proxy_set_header Host $proxy_host;
proxy_set_header Connection close;
To change these setting, as well as modify other header fields, use the "proxy_set_header" directive.
This directive can be specified in a location or higher.
It can also be specified in a particular server context or in the http block
server {
listen 80;
server_name www.system-in-motion.com;
root [location context];
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080/;
}
}
comment:
part 1.context£º
In practical application£¬we may need get client ip address to judge if land in different places£¬or statistic ip access times.
In normal, we get client ip by request.getRemoteAddr()£¬but when we use nginx as reverse proxy£¬
it will get nginx server ip address, (the value of $remote_addr is nginx server ip)
part 2.solution:
server {
listen 88;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /{
root html;
index index.html index.htm;
proxy_pass http://backend;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-For $http_x_forwarded_for;
}
if we want to get client real ip in web server£¬we must do some settings in nginx, for example£º
1. proxy_set_header X-real-ip $remote_addr;
X-real-ip is a custom variable name£¬
then, the client ip is set in X-real-ip, we can get real value in web by request.getAttribute("X-real-ip")
2. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
It's mean add $proxy_add_x_forwarded_for to X-Forwarded-For, not overried;
X-Forwarded-For£¬exploit by squid£¬to identify client ip who access to web server through http proxy or load balancer,
which not follow RFC standard;
if set X-Forwarded-For,it will record each forward by proxy,The format is client1, proxy1, proxy2.
Because of not RFC standard£¬it's null defaultly.
it's mean we cannot get client ip by request.getAttribute("X-Forwarded-For").
For example£¬when visit web through two nginx:
In first nginx, add
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
now, $proxy_add_x_forwarded_for "X-Forwarded-For" is null£¬there is only $remote_addr£¬and the value of $remote_addr is client ip£¬
After assignment£¬the value of X-Forwarded-For is client real ip.
In second nginx£¬add
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
now, $proxy_add_x_forwarded_for£¬X-Forwarded-For contains client real ip£¬the value of $remote_addr is the first nginx ip address£¬
After assignment£¬The value of X-Forwarded-For will become ¡°client ip£¬first nginx ip¡±¡£
3. X-Forwarded-For $http_x_forwarded_for:
by default, X-Forwarded-For is null£¬
so, when only use 'proxy_set_header X-Forwarded-For $http_x_forwarded_for'£¬
u will find the value of request.getAttribute("X-Forwarded-For") is null¡£
if u want to get client real ip through request.getAttribute("X-Forwarded-For")£¬
we should use 'proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for';
make 安装(未成功,仅作记录)
tar zxvf nginx-1.9.9.tar.gz cd nginx-1.9.9 sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install openssl libssl-dev ./configure --with-http_stub_status_module --with-http_gzip_static_module
-- prefix=/usr/local/nginx make
make install cd /usr/local/nginx
sbin/nginx #redhat
yum install *gcc*
yum -y install pcre-devel openssl openssl-devel
NGINX 安装于配置的更多相关文章
- 阿里云服务器Linux CentOS安装配置(八)nginx安装、配置、域名绑定
阿里云服务器Linux CentOS安装配置(八)nginx安装.配置.域名绑定 1.安装nginx yum -y install nginx 2.启动nginx service nginx star ...
- ubuntu server nginx 安装与配置
ubuntu server nginx 安装与配置 一:关于nginx http://wiki.ubuntu.org.cn/Nginx http://nginx.org/cn http://wiki. ...
- Nginx安装及配置详解【转】
nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行网站的发布处理,另外 ...
- [转帖]Nginx安装及配置详解 From https://www.cnblogs.com/zhouxinfei/p/7862285.html
Nginx安装及配置详解 nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP ...
- Linux中Nginx安装与配置详解
转载自:http://www.linuxidc.com/Linux/2016-08/134110.htm Linux中Nginx安装与配置详解(CentOS-6.5:nginx-1.5.0). 1 N ...
- centos7系统下nginx安装并配置开机自启动操作
准备工作 我的centos7系统是最小化安装的, 缺很多库, 首先安装必须的运行库 ? 1 2 3 4 5 6 7 8 9 10 11 yum install wget gcc gcc-c++ pcr ...
- linux nginx安装以及配置
一.Nginx简介 Nginx (“engine x”) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由Igor Sysoev为俄罗斯访问量第二的R ...
- Nginx安装以及配置
安装编译工具及库文件 1 yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel 安装 PCRE 下载 PC ...
- Nginx安装与配置-Centos7
Nginx是一款高性能免费开源网页服务器,也可用于反向代理和负载均衡服务器.该软件由伊戈尔·赛索耶夫于2004年发布,2019年3月11日,Nginx被F5 Networks以6.7亿美元收购.201 ...
- LVS+Nginx(LVS + Keepalived + Nginx安装及配置)
(也可以每个nginx都挂在上所有的应用服务器) nginx大家都在用,估计也很熟悉了,在做负载均衡时很好用,安装简单.配置简单.相关材料也特别多. lvs是国内的章文嵩博士的大作,比nginx被广 ...
随机推荐
- 【杂谈】线程中断——Interrupt
前言 以前有一个错误的认识,以为中断操作都会抛出异常,后来才发现并不是这样,所以今天就来做一个关于中断的总结. 如何关闭线程 已被弃用的Stop方法 早期,Thread类中有一个stop方法,用于强行 ...
- mysql 循环
DELIMITER $$ DROP PROCEDURE IF EXISTS student_insert_while; $$ ), in birthday date, in age int) begi ...
- 如何做自己的服务监控?spring boot 2.x服务监控揭秘
Actuator是spring boot项目中非常强大一个功能,有助于对应用程序进行监视和管理,通过 restful api请求来监管.审计.收集应用的运行情况,针对微服务而言它是必不可少的一个环节. ...
- python argparse(参数解析模块)
这是一个参数解析,可以用它快捷的为你的程序生成参数相关功能 import argparse(导入程序参数模块) # 创建argparse对象,并将产品简要说明加入show = '程序说明' ===&g ...
- 关于EF实体类的一点思考
在EF中修改一条记录时,一般是先查出该条记录,然后再通过TryUpdateModel或其他方式更新对应的属性.但我很讨厌这种要更新一条记录时,还要先去把记录查询出来的做法.我喜欢像sql语句那样的直接 ...
- Git Extensions system.invalidoperationexception尚未提供文件名,因此无法启动进程
根据别人的博客按照步骤安装,地址如下:http://www.cnblogs.com/sorex/archive/2011/08/10/2132359.html 但是安装Git Extensions后生 ...
- vue-cli脚手架搭建项目简单入门一
搭建系统: Windows系统 简单了解Node.js.npm,安装Node.js,下载网址:http://nodejs.cn/download/ 查看node,npm安装成功与否.打开cmd命令行, ...
- linux下如何批量杀JAVA进程或某个进程方法
linux下如何批量杀JAVA进程或某个进程方法 在工作中经常需要停止JAVA进程,停止时间也比较长,那么有时候因为一些情况,需要把 linux 下JAVA所有进程 kill 掉,又不能用killal ...
- Java并发编程:Java的四种线程池的使用,以及自定义线程工厂
目录 引言 四种线程池 newCachedThreadPool:可缓存的线程池 newFixedThreadPool:定长线程池 newSingleThreadExecutor:单线程线程池 newS ...
- 重定向,/dev/null, 1>, 2>什么意思?
文件描述符我们常见的就是系统预留的0,1和2这三个,他们的意义分别有如下对应关系: 0 —— stdin(标准输入) 1 —— stdout (标准输出) 2 —— stderr (标准错误) 其中, ...