add config and add log message
This commit is contained in:
parent
4ce1a59d14
commit
2d8abba3db
69
config.json
69
config.json
|
@ -37,12 +37,12 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"servers":[{
|
"servers":[{
|
||||||
"port": 8000,
|
"port": 3000,
|
||||||
"name": "cloudops",
|
"name": "cloudops",
|
||||||
"paths":[
|
"paths":[
|
||||||
{
|
{
|
||||||
"path": "/",
|
"path": "/",
|
||||||
"upstreams": ["http://192.168.12.174:9880"],
|
"upstreams": ["http://localhost:4200"],
|
||||||
"directives":["HostSchemas $target"]
|
"directives":["HostSchemas $target"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -55,6 +55,71 @@
|
||||||
"upstreams": ["http://192.168.12.174:9880"],
|
"upstreams": ["http://192.168.12.174:9880"],
|
||||||
"directives":["HostSchemas $target"]
|
"directives":["HostSchemas $target"]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path" : "/security/login",
|
||||||
|
"upstreams": ["http://192.168.12.174:9880"],
|
||||||
|
"directives":["HostSchemas $target"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path" : "/security/logout",
|
||||||
|
"upstreams": ["http://192.168.12.174:9880"],
|
||||||
|
"directives":["HostSchemas $target"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path" : "/v1/relational/assets",
|
||||||
|
"upstreams": ["http://192.168.12.174:9880"],
|
||||||
|
"directives":["HostSchemas $target"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path" : "/platform/version",
|
||||||
|
"upstreams": ["http://192.168.12.174:9880"],
|
||||||
|
"directives":["HostSchemas $target"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path" : "/v1/patrolrecords",
|
||||||
|
"upstreams": ["http://192.168.12.174:9880"],
|
||||||
|
"directives":["HostSchemas $target"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path" : "/v1/standingbook",
|
||||||
|
"upstreams": ["http://192.168.12.174:9880"],
|
||||||
|
"directives":["HostSchemas $target"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path" : "/v1/resource",
|
||||||
|
"upstreams": ["http://192.168.12.174:9880"],
|
||||||
|
"directives":["HostSchemas $target"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path" : "/v1/config",
|
||||||
|
"upstreams": ["http://192.168.12.174:9880"],
|
||||||
|
"directives":["HostSchemas $target"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path" : "/v1/workflow",
|
||||||
|
"upstreams": ["http://192.168.12.174:9880"],
|
||||||
|
"directives":["HostSchemas $target"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path":"/token/check",
|
||||||
|
"upstreams": ["http://192.168.12.174:9880"],
|
||||||
|
"directives":["HostSchemas $target"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path" : "/v1/messages",
|
||||||
|
"upstreams": ["http://192.168.12.174:9880"],
|
||||||
|
"directives":["HostSchemas $target"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path" : "/cloudops-state/",
|
||||||
|
"upstreams": ["http://192.168.12.174:9880"],
|
||||||
|
"directives":["HostSchemas $target"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path":"/socket.io/",
|
||||||
|
"upstreams": ["http://192.168.12.174:9880"],
|
||||||
|
"directives":["HostSchemas $target"]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path" : "/thing",
|
"path" : "/thing",
|
||||||
"upstreams": ["http://192.168.12.174:9880"],
|
"upstreams": ["http://192.168.12.174:9880"],
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,20 +1,25 @@
|
||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.pyer.club/kingecg/gohttpd/model"
|
"git.pyer.club/kingecg/gohttpd/model"
|
||||||
|
"git.pyer.club/kingecg/gologger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProxyHandler struct {
|
type ProxyHandler struct {
|
||||||
proxy []*httputil.ReverseProxy
|
proxy []*httputil.ReverseProxy
|
||||||
|
Upstreams []string
|
||||||
count int
|
count int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (p *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
l := gologger.GetLogger("Proxy")
|
||||||
|
originalUrl := r.Host + r.URL.String()
|
||||||
s, err := r.Cookie("s")
|
s, err := r.Cookie("s")
|
||||||
var proxyIndex int
|
var proxyIndex int
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -26,6 +31,8 @@ func (p *ProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
} else {
|
} else {
|
||||||
proxyIndex, _ = strconv.Atoi(s.Value)
|
proxyIndex, _ = strconv.Atoi(s.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
l.Info(fmt.Sprintf("proxy %s to %s", originalUrl, p.Upstreams[proxyIndex]))
|
||||||
p.proxy[proxyIndex].ServeHTTP(w, r)
|
p.proxy[proxyIndex].ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +92,9 @@ func NewProxyHandler(p *model.HttpPath) *ProxyHandler {
|
||||||
if upstreamCount == 0 {
|
if upstreamCount == 0 {
|
||||||
panic("no upstream defined")
|
panic("no upstream defined")
|
||||||
}
|
}
|
||||||
ph := &ProxyHandler{}
|
ph := &ProxyHandler{
|
||||||
|
Upstreams: p.Upstreams,
|
||||||
|
}
|
||||||
ph.proxy = make([]*httputil.ReverseProxy, upstreamCount)
|
ph.proxy = make([]*httputil.ReverseProxy, upstreamCount)
|
||||||
|
|
||||||
for index, upstream := range p.Upstreams {
|
for index, upstream := range p.Upstreams {
|
||||||
|
|
|
@ -0,0 +1,238 @@
|
||||||
|
|
||||||
|
#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 application/octet-stream;
|
||||||
|
|
||||||
|
# Change the upload max request body size to 20M at global
|
||||||
|
client_max_body_size 20m;
|
||||||
|
|
||||||
|
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||||
|
# '$status $body_bytes_sent "$http_referer" '
|
||||||
|
# '"$http_user_agent" "$http_x_forwarded_for"';
|
||||||
|
|
||||||
|
#access_log logs/access.log main;
|
||||||
|
|
||||||
|
sendfile on;
|
||||||
|
#tcp_nopush on;
|
||||||
|
|
||||||
|
#keepalive_timeout 0;
|
||||||
|
keepalive_timeout 65;
|
||||||
|
|
||||||
|
#gzip on;
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 3000;
|
||||||
|
server_name 0.0.0.0;
|
||||||
|
gzip on;
|
||||||
|
gzip_min_length 1k;
|
||||||
|
gzip_buffers 16 64k;
|
||||||
|
gzip_http_version 1.1;
|
||||||
|
gzip_comp_level 6;
|
||||||
|
gzip_types text/plain application/javascript text/css application/xml;
|
||||||
|
gzip_vary on;
|
||||||
|
|
||||||
|
#root /Users/ouka/cloudops;
|
||||||
|
#error_page 404 /index.html;
|
||||||
|
|
||||||
|
# Change the upload max request body size to 20M at this range
|
||||||
|
client_max_body_size 20m;
|
||||||
|
|
||||||
|
#charset koi8-r;
|
||||||
|
|
||||||
|
add_header X-XSS-Protection "1";
|
||||||
|
add_header X-Frame-Options "SAMEORIGIN";
|
||||||
|
#add_header Content-Security-Policy "default-src self; script-src unsafe-inline";
|
||||||
|
add_header X-Content-Type-Options "nosniff";
|
||||||
|
|
||||||
|
#access_log logs/host.access.log main;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
#root /Users/ouka/cloudops;
|
||||||
|
#index index.html index.htm;
|
||||||
|
proxy_pass http://localhost:4200;
|
||||||
|
proxy_cookie_path / "/; secure; SameSite=Lax";
|
||||||
|
}
|
||||||
|
|
||||||
|
location /security/login {
|
||||||
|
proxy_pass http://localhost:7000;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /security/logout {
|
||||||
|
proxy_pass http://localhost:7000;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /token/check {
|
||||||
|
proxy_pass http://localhost:7000;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /v1/relational/assets {
|
||||||
|
proxy_pass http://localhost:7030;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /platform/version {
|
||||||
|
proxy_pass http://localhost:7000;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /v1/patrolrecords {
|
||||||
|
proxy_pass http://localhost:7010;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /v1/standingbook {
|
||||||
|
proxy_pass http://localhost:7010;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /v1/resource {
|
||||||
|
proxy_pass http://localhost:7010;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /themes {
|
||||||
|
proxy_pass http://localhost:9980;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ^~ /v1/config {
|
||||||
|
proxy_pass http://localhost:5433;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ^~ /v1/workflow {
|
||||||
|
proxy_pass http://localhost:5433;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ^~ /v1/messages {
|
||||||
|
proxy_pass http://localhost:5433;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /cloudops-state/ {
|
||||||
|
# /socket.io/ is the default socket.io server serving path
|
||||||
|
# so only proxy socket.io request, without expose mbus:/v1/... pages
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_read_timeout 600s;
|
||||||
|
proxy_pass http://localhost:7012;
|
||||||
|
#proxy_pass http://192.168.12.205:7012;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /socket.io/ {
|
||||||
|
# /socket.io/ is the default socket.io server serving path
|
||||||
|
# so only proxy socket.io request, without expose mbus:/v1/... pages
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_pass http://localhost:39092;
|
||||||
|
#proxy_pass http://192.168.12.205:39092;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /sockjs-node/ {
|
||||||
|
# /socket.io/ is the default socket.io server serving path
|
||||||
|
# so only proxy socket.io request, without expose mbus:/v1/... pages
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_pass http://localhost:4200;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /ws {
|
||||||
|
# /socket.io/ is the default socket.io server serving path
|
||||||
|
# so only proxy socket.io request, without expose mbus:/v1/... pages
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_pass http://localhost:4200;
|
||||||
|
}
|
||||||
|
|
||||||
|
#location / {
|
||||||
|
# root html;
|
||||||
|
# index index.html index.htm;
|
||||||
|
#}
|
||||||
|
|
||||||
|
#error_page 404 /404.html;
|
||||||
|
|
||||||
|
# redirect server error pages to the static page /50x.html
|
||||||
|
#
|
||||||
|
error_page 500 502 503 504 /50x.html;
|
||||||
|
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:9000
|
||||||
|
#
|
||||||
|
#location ~ \.php$ {
|
||||||
|
# root html;
|
||||||
|
# fastcgi_pass 127.0.0.1:9000;
|
||||||
|
# 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;
|
||||||
|
#}
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 3201;
|
||||||
|
server_name 0.0.0.0;
|
||||||
|
|
||||||
|
# Change the upload max request body size to 20M at this range
|
||||||
|
client_max_body_size 20m;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://localhost:4201;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /v1/relational/assets {
|
||||||
|
proxy_pass http://localhost:7030;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /socket.io/ {
|
||||||
|
# /socket.io/ is the default socket.io server serving path
|
||||||
|
# so only proxy socket.io request, without expose mbus:/v1/... pages
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_pass http://localhost:39092;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /cloudops-state/ {
|
||||||
|
# /socket.io/ is the default socket.io server serving path
|
||||||
|
# so only proxy socket.io request, without expose mbus:/v1/... pages
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_pass http://localhost:7012;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /sockjs-node/ {
|
||||||
|
# /socket.io/ is the default socket.io server serving path
|
||||||
|
# so only proxy socket.io request, without expose mbus:/v1/... pages
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_pass http://localhost:4200;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -224,7 +224,8 @@ func (s *ServerMux) AddDirective(directiveStr string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServerMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *ServerMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
l := logger.GetLogger("ServerMux")
|
l := logger.GetLogger("Access")
|
||||||
|
l.Info(fmt.Sprintf("From %s-%s %s", r.RemoteAddr, r.Method, r.URL.Path))
|
||||||
for _, p := range s.paths {
|
for _, p := range s.paths {
|
||||||
if strings.HasPrefix(r.URL.Path, p) {
|
if strings.HasPrefix(r.URL.Path, p) {
|
||||||
l.Info(fmt.Sprintf("match path: %s", p))
|
l.Info(fmt.Sprintf("match path: %s", p))
|
||||||
|
@ -233,7 +234,7 @@ func (s *ServerMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
l.Info(fmt.Sprintf("not match path: %s", r.URL.Path))
|
l.Error(fmt.Sprintf("404: %s", r.URL.Path))
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue