Nginx $uri $request_uri $request_filename 与 location(root/alias)
1 2 3 4 5 6 7 8 9 10 11
| 浏览器请求 /scanQRCodePayPark/ $uri $request_uri $request_filename /scanQRCodePayPark/index.html /scanQRCodePayPark/ /home/www/html/scanQRCodePayPark/index.html
浏览器请求 /scanQRCodePayPark/index.html $uri $request_uri $request_filename /scanQRCodePayPark/index.html /scanQRCodePayPark/index.html /home/www/html/scanQRCodePayPark/index.html
浏览器请求 /scanQRCodePayPark/?qs=123 $uri $request_uri $request_filename /scanQRCodePayPark/index.html /scanQRCodePayPark/?qs=123 /home/www/html/scanQRCodePayPark/index.html
|
vuejs nginx config
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| server { listen 80; server_name www.boer.xyz; location / { root /home/www/html; index index.html index.htm; try_files $uri $uri/ /index.html; if ($uri ~ .*\.(html|htm)$) { add_header Cache-Control no-cache; add_header X-Boer-Define love-boer; } } location ~ .*\.(html|htm)$ { root /home/www/html; add_header Cache-Control no-cache; add_header X-Boer-Define love-boer; } }
|
nginx json log
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| log_format json_combined escape=json '{' '"time_local":"$time_local",' '"remote_addr":"$remote_addr",' '"remote_user":"$remote_user",' '"request":"$request",' '"status": "$status",' '"body_bytes_sent":"$body_bytes_sent",' '"request_time":"$request_time",' '"http_referrer":"$http_referer",' '"http_user_agent":"$http_user_agent",' '"http_x_forwarded_for":"$http_x_forwarded_for"' '}'; access_log /var/log/nginx/access.log json_combined;
|
backend http-ws,https-wss config
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| map $http_upgrade $connection_upgrade { default upgrade; '' close; } upstream backend { server 10.10.253.16:8090 weight=5; } server { listen 80; listen 443 ssl; server_name waf.boer.xyz;
## http://nginx.org/en/docs/http/ngx_http_ssl_module.html ssl_certificate /etc/nginx/ssl/waf.boer.xyz/cert.pem; ssl_certificate_key /etc/nginx/ssl/waf.boer.xyz/key.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; ssl_session_timeout 5m; ssl_session_cache shared:SSL:10m;
access_log /var/log/nginx/$server_name.access.log json_combined;
location / { proxy_pass http://backend; 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_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } }
; 1、打包地址 VUE_APP_PUBLIC_PATH = '/' ; 2、接口地址 VUE_APP_BASE_API = '//api.boer.xyz' # 相对协议URL ; 3、Websocket地址 ; initWebSocket() { ; let url = window.location.href ; let wsuri; ; if (url.indexOf('https://iot.boer.xyz') !== -1) { ; wsuri = "wss://api.boer.xyz/inoutRecord/ws?userId=" + getUserId(); ; } else if (url.indexOf('http://iot.boer.xyz') !== -1) { ; wsuri = "ws://api.boer.xyz/inoutRecord/ws?userId=" + getUserId(); ; }else { ; wsuri = "ws://api.boer.xyz/inoutRecord/ws?userId=" + getUserId(); ; } ; this.websock = new WebSocket(wsuri); ; this.websock.onmessage = this.websocketonmessage; ; this.websock.onopen = this.websocketonopen; ; this.websock.onerror = this.websocketonerror; ; this.websock.onclose = this.websocketclose; ; }
|
Ref