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 安装于配置的更多相关文章

  1. 阿里云服务器Linux CentOS安装配置(八)nginx安装、配置、域名绑定

    阿里云服务器Linux CentOS安装配置(八)nginx安装.配置.域名绑定 1.安装nginx yum -y install nginx 2.启动nginx service nginx star ...

  2. ubuntu server nginx 安装与配置

    ubuntu server nginx 安装与配置 一:关于nginx http://wiki.ubuntu.org.cn/Nginx http://nginx.org/cn http://wiki. ...

  3. Nginx安装及配置详解【转】

    nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP服务器进行网站的发布处理,另外 ...

  4. [转帖]Nginx安装及配置详解 From https://www.cnblogs.com/zhouxinfei/p/7862285.html

    Nginx安装及配置详解   nginx概述 nginx是一款自由的.开源的.高性能的HTTP服务器和反向代理服务器:同时也是一个IMAP.POP3.SMTP代理服务器:nginx可以作为一个HTTP ...

  5. Linux中Nginx安装与配置详解

    转载自:http://www.linuxidc.com/Linux/2016-08/134110.htm Linux中Nginx安装与配置详解(CentOS-6.5:nginx-1.5.0). 1 N ...

  6. centos7系统下nginx安装并配置开机自启动操作

    准备工作 我的centos7系统是最小化安装的, 缺很多库, 首先安装必须的运行库 ? 1 2 3 4 5 6 7 8 9 10 11 yum install wget gcc gcc-c++ pcr ...

  7. linux nginx安装以及配置

    一.Nginx简介 Nginx (“engine x”) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由Igor Sysoev为俄罗斯访问量第二的R ...

  8. Nginx安装以及配置

    安装编译工具及库文件 1 yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel 安装 PCRE 下载 PC ...

  9. Nginx安装与配置-Centos7

    Nginx是一款高性能免费开源网页服务器,也可用于反向代理和负载均衡服务器.该软件由伊戈尔·赛索耶夫于2004年发布,2019年3月11日,Nginx被F5 Networks以6.7亿美元收购.201 ...

  10. LVS+Nginx(LVS + Keepalived + Nginx安装及配置)

    (也可以每个nginx都挂在上所有的应用服务器)  nginx大家都在用,估计也很熟悉了,在做负载均衡时很好用,安装简单.配置简单.相关材料也特别多. lvs是国内的章文嵩博士的大作,比nginx被广 ...

随机推荐

  1. Python 【web框架】之Flask

    flask 是Python实现的轻量级web框架.没有表单,orm等,但扩展性很好.很多Python web开发者十分喜欢.本篇介绍flask的简单使用及其扩展. 文中示例源码已经传到github:h ...

  2. JavaWeb学习(二十二)———EL表达式

    一.EL表达式简介 EL 全名为Expression Language.EL主要作用: 1.获取数据 EL表达式主要用于替换JSP页面中的脚本表达式,以从各种类型的web域 中检索java对象.获取数 ...

  3. 使用Asp.Net Core MVC 开发项目实践[第五篇:缓存的使用]

    项目中我们常常会碰到一些数据,需要高频率用到但是又不会频繁变动的这类,我们就可以使用缓存把这些数据缓存起来(比如说本项目的导航数据,帖子频道数据). 我们项目中常用到有Asp.Net Core 本身提 ...

  4. svgalib_1.4.3 移植

    运行环境 RedHat 6.3 Linux localhost 2.6.32-279.el6.i686 需准备好的文件: libx86_1.1+ds1.orig.tar.gz libx86_1.1+d ...

  5. GNU μC/OS-II 在 S3C2440 上中断的实现

    上一篇文章介绍了S3c2440的中断体系结构,今天我们来分析一下GNU-uC/OS-II在S3c2440上中断的实现. 首先找到IRQ的中断的向量,位于 2440init.S : OK ,我们通过名字 ...

  6. 哆啦A梦欺骗了你!浏览器CSS3测试遭质疑

    首先,说明,此处只是告诫各位参与CSS3.0学习使用或者将要使用或者学习CSS3.0的朋友,不要完全信任网络资源,依靠网络资源,我们需要利用网络资源的方便和可取的部分,结合自己的理解,学好,理解好! ...

  7. (转)Linux企业运维人员最常用150个命令汇总

    目录 线上查询及帮助命令(2个) 文件和目录操作命令(18个) 查看文件及内容处理命令(21个) 文件压缩及解压缩命令(4个) 信息显示命令(11个) 搜索文件命令(4个) 用户管理命令(10个) 基 ...

  8. Ubuntu下redis允许外部链接

    原文地址: https://blog.csdn.net/a150827/article/details/51352395 redis在ubuntu安装后默认是只有本地访问,需要别的ip访问我们需要修改 ...

  9. (2)Microsoft office Word 2013版本操作入门_快速选中

    1.快速选中一行 .一段文字: 1.1光标在一行内,双击会选中一个词组.快速点击三下会选中一段, 1.2 鼠标移动到行首,单击击会选中一行,双击选中一段. 1.3 选择全部内容 Ctrl+A  , 1 ...

  10. 学了9天java,没什么感觉,有点害怕,总结一下for循环。

    for(int i=0; i<100; i++){ if(i%3==0){ continue://满足条件的跳过 } System.out.print(i); } //最后输出的数中没有满足3的 ...