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被广 ...
随机推荐
- postgresql 清空数据表 truncate
在 mysql 中如果需要清空表,只需要 TRUNCATE table_name; 即可,如果有自增的 id 字段,也会还原回 1, 但是 postgresql 与 mysql 稍有不同,postgr ...
- EOS行为核心:解析插件chain_plugin
EOS提供了大量的rpc接口,其中功能性最强,使用最频繁的一部分接口是EOS的行为核心,由chain_api_plugin提供,具体实现是在chain_plugin. 关键字:EOS,区块链,chai ...
- leetcode — string-to-integer-atoi
/** * Source : https://oj.leetcode.com/problems/string-to-integer-atoi/ * * Created by lverpeng on 2 ...
- Struts的FormFile与Commons-FileUpload控件使用心得
转自: http://www.iteye.com/topic/212566 前一段时间刚来公司,看到一个项目中以前有人写的struts代码.是使用了FormFile来处理关于文件上传的模块.但是用力一 ...
- spring-boot-2.0.3启动源码篇 - 阶段总结
前言 开心一刻 朋友喜欢去按摩,第一次推门进来的是一个学生美眉,感觉还不错:后来经常去,有时是护士,有时是空姐,有时候是教师.昨天晚上推门进去的是一个女警察,长得贼好看,身材也很好,朋友嗷的一声就扑上 ...
- Maven deploy 部署 jar+pom 到 Nexus 私服
经验之谈 工作中,我们常常需要将基础架构部门的 jar 包提供给业务部门的同事使用,那么,需要将 jar 包 deploy 到 nexus 私服上,网上资料不是很多,这里说一下具体细节. 首先,是打 ...
- 菜鸟入门【ASP.NET Core】5:命令行配置、Json文件配置、Bind读取配置到C#实例、在Core Mvc中使用Options
命令行配置 我们通过vs2017创建一个控制台项目CommandLineSample 可以看到现在项目以来的是dotnet core framework 我们需要吧asp.net core引用进来 ...
- Python全栈学习_day004作业
,写代码,有如下列表,按照要求实现每一个功能 li = ["alex", "WuSir", "ritian", "barry&qu ...
- Csharp: read Sybase SQL anywhere5.5 using c#
private void button1_Click(object sender, EventArgs e) { try { //OdbcConnection conn = new OdbcConne ...
- MySql Host is blocked because of many connection errors; unblock with 'mysqladmi
原因: 同一个ip在短时间内产生太多(超过mysql数据库max_connection_errors的最大值)中断的数据库连接而导致的阻塞: 解决方法: 1.提高允许的max_connection_e ...