跳到主要内容

v3-app-nginx.conf

v3手机端nginx配置

#user  nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type 'text/html';
client_max_body_size 20000M;

#修改日志格式
log_format main escape=json '{ "time": "$year-$month-$day $hour:$minutes:$seconds", '
'"request_id": "$request_id",'
'"request": "$request",'
'"remote_addr": "$remote_addr",'
'"costime": "$request_time",'
'"realtime": "$upstream_response_time",'
'"status": $status,'
'"x_forwarded": "$http_x_forwarded_for",'
'"referer": "$http_referer",'
'"upstr_addr": "$upstream_addr",'
'"bytes":$body_bytes_sent,'
'"body": "$request_body",'
'"agent": "$http_user_agent" },';

access_log logs/$year-$month-$day-$hour-access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 30789;
server_name localhost;
add_header X-Frame-Options SAMEORIGIN;

charset utf-8;
#截取日志
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
set $hour $4;
set $minutes $5;
set $seconds $6;
}
if ($request_method = OPTIONS ) {
return 403;
}

#access_log logs/host.access.log main;

location / {
if ($request_filename ~* .*.(html|htm)$)
{
expires -1s;
}
if ($request_filename ~* .*.(gif|jpg|jpeg|png|bmp|swf)$)
{
expires 30d;
}
if ($request_filename ~ .*.(js|css)$)
{
expires 12h;
}
root html;
index index.html index.htm;
}

location ^~ /images {
rewrite /images/(.*) /static/$1 last;
}
location ^~ /Dual {
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_pass http://192.168.1.13:9877;
# access_log "logs/test.log";
}
location /rs/safePsoition/savePosition {
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_pass http://127.0.0.1:8003/safecheck/rs/safePsoition/savePosition;
}
#在Lua中访问Redis
location /redis {
set_by_lua $mykey '
return string.gsub(ngx.var.arg_key, "%%(%x%x)", function(h) return string.char(tonumber(h, 16)) end)
';
internal; #只能内部访问
redis2_query auth AofengPassw0rd!;
redis2_query get $mykey;
redis2_pass '127.0.0.1:8000';
}

#取安检图片,转发到安检
location ^~/rs/image/file {
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_pass http://127.0.0.1:8003/safecheck/rs/image/file;
# access_log "logs/test.log";
}
location /phone {
content_by_lua '
ngx.say("ok")
';
}
location /webapps/safecheck {
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_pass http://127.0.0.1:8003/safecheck;
}
# oa请求
location ^~/phoneoa/rs/sql/ {
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_pass http://121.36.59.193:8006/telephone/rs/sql/;
}
location ^~/phoneoa/rs/logic {
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_pass http://121.36.59.193:8006/telephone/rs/logic;
}
location /phone/rs/dir/global/ {
proxy_method POST;
proxy_pass http://127.0.0.1:8006/telephone/rs/dir/global;
break;
}
location /safecheck/update.apk/ {
proxy_method POST;
proxy_pass http://127.0.0.1:8003/safecheck/update.apk;
}

location /phone/update.apk {
proxy_method GET;
proxy_pass http://127.0.0.1:8003/safecheck/update.apk;
}

location /phone/rs/dir/version/ {
proxy_pass http://127.0.0.1:8006/telephone/rs/dir/version;
}

#获取数据表元数据
location /phone/rs/db {
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_pass http://127.0.0.1:8002/manage/rs/db;
}

#返回所有文件名
location /phone/rs/dir/ {
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_pass http://127.0.0.1:8006/telephone/rs/dir;
}

#取业务逻辑等后台组件内容
location /phone/rs/dir2 {
#把安检、维修等模块内容统一发送回去
content_by_lua '
--如果body有内容,返回给定业务逻辑内容
ngx.req.read_body()
local resp_body = ngx.req.get_body_data()
if resp_body ~= nil then
ngx.log(ngx.INFO, "resp_body:" .. resp_body)
resp_body = string.gsub(resp_body, "\\\\", "/")
local part = string.match(resp_body, "/(.+)%.")
-- 从redis里获取地址,转发到对应地址去
local parser = require("redis.parser")
local res = ngx.location.capture("/redis", {
args = { key = part }
})
if res.status == 200 then
res.body = string.sub(res.body,6)
local reply = parser.parse_reply(res.body)
return ngx.exec("/file2", {url = reply})
end
end
--定义获取内容的地址
local array = {
"http://127.0.0.1:8006/telephone",
"http://127.0.0.1:8003/safecheck",
"http://127.0.0.1:8002/system"
}
--对每一个地址,通过转发获取内容,进行拼接
local result = ""
for k,v in ipairs(array) do
local res = ngx.location.capture("/dir2", {
method = ngx.HTTP_GET,
args = { key = v }
})
if res.status == 200 and res.body ~= "" then
if result == "" then
result = res.body
else
result = result .. "|" .. res.body
end
end
end
ngx.print(result)
';
}

#取vue配置
location /phone/rs/vue {
content_by_lua '
--定义获取内容的地址
local array = {
"http://127.0.0.1:8006/telephone",
"http://127.0.0.1:8003/safecheck",
"http://127.0.0.1:8002/system"
}
--对每一个地址,通过转发获取内容,进行拼接
local result = ""
for k,v in ipairs(array) do
local res = ngx.location.capture("/vue2", {
method = ngx.HTTP_GET,
args = { key = v }
})
--截取array中最后"/"后的值
local ts = string.reverse(v)
local param1, param2 = string.find(ts, "/")
local m = string.len(v) - param2 + 1
v = string.sub(v, m+1, string.len(v))
v = [["]] .. v .. [["]]
--拼接字符串
if res.status == 200 and res.body ~= "" then
if result == "" then
result =v .. ":" .. res.body
else
result = result .. "," .. v .. ":" .. res.body
end
end
end
result = "{" .. result .. "}"
ngx.print(result)
';
}

#获取模块内容
location /vue2 {
internal;
set_by_lua $myurl '
local result = string.gsub(ngx.var.arg_key, "%%(%x%x)", function(h) return string.char(tonumber(h, 16)) end)
return result
';
proxy_pass $myurl/rs/vue;
}
#获取模块内容
location /dir2 {
internal;
set_by_lua $myurl '
local result = string.gsub(ngx.var.arg_key, "%%(%x%x)", function(h) return string.char(tonumber(h, 16)) end)
return result
';
proxy_pass $myurl/rs/dir2/noxml;
}
#phone的业务逻辑访问等内容,直接重写到本服务
location ~ /phone/rs/(logic|sql|path|entity) {
rewrite /phone/rs/(.*) /rs/$1 last;
}

#获取模块文件内容
location /file2 {
set_by_lua $myurl '
local result = string.gsub(ngx.var.arg_url, "%%(%x%x)", function(h) return string.char(tonumber(h, 16)) end)
return result
';
proxy_pass http://$myurl/rs/dir2;
}


location /rs/logic {#需要LuaRedisParser
if ($request_uri ~ /rs/logic/(.+))
{
#取得业务逻辑名
set $params $1;
}
#根据业务逻辑名获得转发地址
rewrite_by_lua '
local parser = require("redis.parser")
local res = ngx.location.capture("/redis", {
args = { key = ngx.var.params }
})
if res.status == 200 then
res.body = string.sub(res.body,6)
local reply = parser.parse_reply(res.body)
return ngx.exec("/logic", {url = reply, logic = ngx.var.params})
end
';
}

location /logic {
if ( $query_string ~* ^url=(.*)&logic=(.*)$ ){
set $url $1;
set $logic $2;
}
if ( $query_string ~* ^logic=(.*)&url=(.*)$ ){
set $url $2;
set $logic $1;
}
set_by_lua $myurl '
local result = string.gsub(ngx.var.url, "%%(%x%x)", function(h) return string.char(tonumber(h, 16)) end)
return result
';
proxy_pass http://$myurl/rs/logic/$logic;
}

location /rs/entity {#需要LuaRedisParser
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_pass http://127.0.0.1:8002/manage/rs/entity;
# access_log "logs/test.log";
}

location ~ /rs/(sql|path) {#需要LuaRedisParser
if ( $request_uri ~ /rs/(sql|path)/([^\?/$]+)(.*)$ ){
#取得业务逻辑名
set $type $1;
set $sql $2;
set $params $3;
}
#长的在后面,会覆盖前面短的
if ( $request_uri ~ /rs/sql/hql/([^\?/$]+)(.*)$ ){
set $type 'sql';
set $sql $1;
set $params $2;
}

#根据业务逻辑名获得转发地址
rewrite_by_lua '
local parser = require("redis.parser")
ngx.var.sql = ngx.unescape_uri(ngx.var.sql)
ngx.var.sql = string.gsub(ngx.var.sql, "%%(%x%x)", function(h) return string.char(tonumber(h, 16)) end)
local res = ngx.location.capture("/redis", {
args = { key = ngx.var.sql }
})
if res.status == 200 then
res.body = string.sub(res.body,6)
local reply = parser.parse_reply(res.body)
return ngx.exec("/sql/"..ngx.var.sql..ngx.var.params, {url = reply, type = ngx.var.type})
end
';
}

location /sql {
if ( $request_uri ~ /(sql|path)/(.+)$ ) {
set $sql $2;
}
set_by_lua $myurl '
local result = string.gsub(ngx.var.arg_url, "%%(%x%x)", function(h) return string.char(tonumber(h, 16)) end)
result = string.gsub(result, "%%(%x%x)", function(h) return string.char(tonumber(h, 16)) end)
return result
';
set_by_lua $mysql '
local result = string.gsub(ngx.var.sql, "%%(%x%x)", function(h) return string.char(tonumber(h, 16)) end)
return result
';
set_by_lua $mytype '
local result = string.gsub(ngx.var.arg_type, "%%(%x%x)", function(h) return string.char(tonumber(h, 16)) end)
return result
';
proxy_pass http://$myurl/rs/$mytype/$mysql;
}
#手机图片上传,直接转发到呼叫模块
location /apply/rs/file/savefile {
proxy_method POST;
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_pass http://127.0.0.1:9600/applyinstall/rs/file/savefile;
# access_log "logs/test.log";
}
#手机图片上传,直接转发到呼叫模块
location /rs/file/savefile {
proxy_method POST;
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_pass http://127.0.0.1:8006/telephone/rs/file/savefile;
# access_log "logs/test.log";
}
#手机图片上传,直接转发到呼叫模块
location /rs/file_new/savefile_new {
proxy_method POST;
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_pass http://127.0.0.1:8006/telephone/rs/file_new/savefile_new;
# access_log "logs/test.log";
}
location /excel/ {
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_pass http://127.0.0.1:8002/manage/excel/;
}

#转发到上传
location /rs/file {
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_pass http://127.0.0.1:8002/revenue/rs/file;
# access_log "logs/test.log";
}


#转发到上传
location /files_picture {
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_pass http://127.0.0.1:8074/files_picture;
# access_log "logs/test.log";
}

#转发到系统服务
location /rs/log {
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_pass http://127.0.0.1:8002/system/rs/log;
# access_log "logs/test.log";
}

#转发到资源服务
location /rs {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'PUT,POST,GET,OPTIONS,DELETE';
add_header Access-Control-Allow-Headers 'x-requested-with,content-type';
if ($request_method = 'OPTIONS') {
return 204;
}
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_pass http://127.0.0.1:8001/ldap/rs;
# access_log "logs/test.log";
}

#转发到报表服务
location /rs/report {
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_pass http://127.0.0.1:8002/manage/rs/report;
# access_log "logs/test.log";
}

#vue转发到system服务
location /rs/vue {
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_pass http://127.0.0.1:8002/system/rs/vue;
# access_log "logs/test.log";
}

location /pos {
content_by_lua '
ngx.say("ok")
';
}

#手机图片下载,直接转发到呼叫模块
location /rs/file/getfile {
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_pass http://127.0.0.1:8006/telephone/rs/file/getfile;
# access_log "logs/test.log";
}

location ~* \.(png)$ {
if ($request_uri ~* "files"){root D:;}
}
location ~* \.(jpg)$ {
if ($request_uri ~* "files"){root D:;}
}
location ~* \.(webp)$ {
if ($request_uri ~* "files"){root D:;}
}
location ~* \.(svg)$ {
if ($request_uri ~* "files"){root D:;}
}
location ~* \.(doc)$ {
if ($request_uri ~* "files"){root D:;}
}
location ~* \.(docx)$ {
if ($request_uri ~* "files"){root D:;}
}
location ~* \.(gif)$ {
if ($request_uri ~* "files"){root D:;}
}
location ~* \.(xlsx)$ {
if ($request_uri ~* "files"){root D:;}
}
location ~* \.(pdf)$ {
if ($request_uri ~* "files"){root D:;}
}
location ~* \.(txt)$ {
if ($request_uri ~* "files"){root D:;}
}
location ~* \.(zip)$ {
if ($request_uri ~* "files"){root D:;}
}
location ~* \.(rar)$ {
if ($request_uri ~* "files"){root D:;}
}
location ~* \.(7z)$ {
if ($request_uri ~* "files"){root D:;}
}



error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location @redirect {
return 301 http://localhost$request_uri;
}
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:8000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:8000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}

# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
#
#
#
#
}