海运的博客

Nginx Proxy细节问题

发布时间:January 18, 2014 // 分类:Nginx // No Comments

1.rewrite使用break结,使用last会对server标签重新发起请求

location /a/ {
    rewrite ^/a/(.*)$ /b/$1 break;
    proxy_pass https://www.haiyun.me;
}

2.proxy_pass结尾添加/会丢弃路径目录,如下访问/a/test.html会代理到/test.html

location /a/ {
    rewrite ^/a/(.*)$ /b/$1 break;
    proxy_pass https://www.haiyun.me/;
}

3.代理访问重定向的网址:

proxy_redirect https://www.haiyun.me/ http://$host/;

Nginx Lua Proxy

发布时间:January 12, 2014 // 分类:Nginx // No Comments

location / {
    set $bindip '';
    content_by_lua_file '/usr/local/nginx/lua/proxy.lua';
} 
location /proxy {
    proxy_pass       "http://$host$request_uri";
    proxy_bind       $bindip;
}
local action = ngx.var.request_method
if action == "POST" then
    method = ngx.HTTP_POST
else
    method = ngx.HTTP_GET
end
res = ngx.location.capture(
    '/proxy', { method = method, always_forward_body = true, copy_all_vars = true }
    )
ngx.print(res.body)
ngx.print(res.status)

Nginx Lua HTTP客户端

发布时间:January 12, 2014 // 分类:Nginx // No Comments

git clone https://github.com/liseen/lua-resty-http.git

Nginx配置:

http
{
    llua_package_path "/path/to/lua-resty-http/lib/?.lua;;";
    server {
        location /test {
            content_by_lua_file '/usr/local/nginx/conf/lua/proxy.lua';
        }
}

Proxy.lua内容:

local http = require "resty.http"
local hc = http:new()
local url = "http://"
if ngx.var.http_host then
    url = url .. ngx.var.http_host 
end
url = url .. ngx.var.request_uri  -- 拼接完整的URL
if ngx.var.args then
    url = url .. "?" .. ngx.var.args
end
--[[
local ok, code, headers, status, body = hc:proxy_pass {
url = url,
proxy = "http://192.168.1.5:8118",
timeout = 3000,
headers = ngx.req.get_headers(), -- 传递客户端HEAD
method = ngx.var.request_method, -- 传递客户端method
method = "GET",
}
]]
local ok, code, headers, status, body = hc:request {
    url = url,
    proxy = "http://192.168.1.5:8118",
    timeout = 3000,
    headers = {UserAgent = "Mozilla/5.0"},
    headers = ngx.req.get_headers(), 
    method = ngx.var.request_method,
}
ngx.say(ok)
ngx.say(code)
ngx.say(body)
ngx.say(url)

更多:http://wendal.net/422.html

Nginx添加Lua支持

发布时间:January 4, 2014 // 分类:Nginx // No Comments

安装LuaJIT:

wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz
tar zxvf LuaJIT-2.0.2.tar.gz 
make && make install PREFIX=/usr/local/luajit2.02
echo "/usr/local/luajit2.02/lib" > /etc/ld.so.conf.d/luajit.conf
export LUAJIT_LIB=/usr/local/luajit2.02/lib/
export LUAJIT_INC=/usr/local/luajit2.02/include/

安装Nginx及Ngx_lua模块:

wget http://nginx.org/download/nginx-1.4.4.tar.gz
tar zxvf nginx-1.4.4.tar.gz 
cd nginx-1.4.4/
wget -O ngx_devel_kit0.2.19.tar.gz https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz
tar zxvf ngx_devel_kit0.2.19.tar.gz
wget -O lua-nginx0.9.3.tar.gz https://github.com/chaoslawful/lua-nginx-module/archive/v0.9.3.tar.gz
tar zxvf lua-nginx0.9.3.tar.gz 
./configure --prefix=/usr/local/nginx1.4.4 --conf-path=/etc/nginx/nginx.conf --with-ipv6 \
--with-http_ssl_module --add-module=./ngx_devel_kit-0.2.19/ --add-module=./lua-nginx-module-0.9.3/ 
make && make install

测试:

location /lua {
    default_type 'text/plain';
    content_by_lua "ngx.print(ngx.var['arg_tag'], '\\n')";
}

访问:

curl -i '192.168.1.2/lua?tag=hello'

CentOS6使用Yum源安装LNMP

发布时间:December 25, 2013 // 分类:Nginx,CentOS // No Comments

编译安装LNMP太繁琐,不易部署和管理,通过系统源安装最很方便,Centos官方源软件包较少,需先安装EPEL源
安装MysQL:

yum install mysql-server
/etc/init.d/mysqld start
chkconfig mysqld on
/usr/bin/mysqladmin -u root password 'newpasswd'

安装PHP:

yum install php-fpm php-cli php-mysqlnd php-pdo php-xml php-gd php-opcache
/etc/init.d/php-fpm start
chkconfig php-fpm on

安装Nginx:

yum install nginx
/etc/init.d/nginx start
chkconfig nginx on
分类
最新文章
最近回复
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...