nginx反向代理后端服務restful及token處理


#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;
}
#代理mysql服務
stream {upstream mysql_backend {server 192.168.10.250:3306 weight=5 max_fails=3 fail_timeout=30s;}server {listen 9016;proxy_connect_timeout 10s;proxy_timeout 300s;proxy_pass mysql_backend;}
}http {include       mime.types;default_type  application/octet-stream;#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;#underscores_in_headers on;#gzip  on;server {listen 9015;server_name  localhost;# 主路徑代理(如/doc)location / {if ($request_method = 'OPTIONS') { return 200;}# 傳遞原始請求頭中的Authorization(Token)proxy_set_header Authorization $http_authorization;proxy_pass http://192.168.10.250:8080/examsystem/;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-Proto $scheme;proxy_set_header Authorization $http_authorization;# 重寫JS/CSS路徑(關鍵配置)#sub_filter '/js/' '/doc/js/';#sub_filter '/css/' '/doc/css/';#sub_filter_once off;}# 不需要Token的接口(如登錄接口)location ^~ /examsystem/itjavatemptable/itjavaTempTable {  # 假設登錄接口路徑為/examsystem/loginproxy_pass http://192.168.10.250:8080;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;# 不傳遞Authorization頭proxy_set_header Authorization "";}# 關鍵配置:重寫webjars路徑,靜態資源處理location ^~ /webjars/ {rewrite ^/webjars/(.*)$ /examsystem/webjars/$1 break;proxy_pass http://192.168.10.250:8080;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-Proto $scheme;}# 靜態資源代理(關鍵配置)#location /webjars/js/ {#    alias http://192.168.10.250:8080/examsystem/webjars/js/;  # 替換為后端實際路徑# 或使用root(需注意路徑拼接)# root /path/to/backend/examsystem/;#}#location /webjars/css/ {#    alias http://192.168.10.250:8080/examsystem/webjars/css/;#}	# 處理/examsystem/路徑下的所有靜態資源#location /examsystem/ {#    proxy_pass http://192.168.10.250:8080/examsystem/;#    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-Proto $scheme;#}# 可選:單獨處理常見靜態資源后綴location ~* \.(css|js|png|jpg|jpeg|gif|ico|woff|woff2|ttf|eot|svg)$ {proxy_pass http://192.168.10.250:8080;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-Proto $scheme;}# 緩存靜態資源(可選,提高性能)expires 7d;add_header Cache-Control "public";#charset koi8-r;#access_log  logs/host.access.log  main;#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;#}}# 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;#    }#}}

上面的nginx配置實現了nginx反向代理后端服務器接口及實現指定接口不進行token驗證的方法。本配置還代理了后端服務器的Mysql服務。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/86937.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/86937.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/86937.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

正確理解Cola StateMachine不內置事務管理機制

? 正確理解:Cola StateMachine 并非“不支持”事務一致性,而是“不內置”事務管理機制 因為: Cola StateMachine 是輕量級、無狀態、不依賴 Spring 的框架,它本身 不綁定任何事務上下文。它不像 Spring StateMachine 那樣自動與…

AudioTrack使用

** AudioTrack ** AudioTrack 是 Android 音頻系統中的核心類,用于播放原始音頻數據(PCM)或壓縮音頻(如 MP3、AAC)。它提供了低級別的音頻播放控制,適合需要精細管理的場景(如游戲音效、實時音…

解密:MySQL 的常見存儲引擎

在數據庫領域,MySQL 作為一款廣受歡迎的關系型數據庫管理系統,提供了多種存儲引擎以滿足不同應用場景的需求。每種存儲引擎都有其獨特的特性、優勢和適用場景。本文將深入探討 MySQL 中幾種常見的存儲引擎,包括 InnoDB、MyISAM、MEMORY 和 AR…

qt和qtcreator版本關系

實例展示: 如圖所示的qtcreator是使用qt5.15安裝過程選擇勾選了qtcreator 14.0.2,安裝完成qtcreator版本信息: 安裝過程中選擇了這些構件kits,會自動識別到: 使用qt5.9.9另外安裝的kits,需要手動設置才能識…

2個任務同時提交到YARN后2個都卡住(CDH)

文章目錄 問題描述解決方案1、增加資源2、調整ApplicationMaster資源3、關閉YARN調度器的資源搶占4、不使用公平調度器 問題描述 在CDH集群上,同時提交2個任務到YARN后,2個任務都卡住 解決方案 1、增加資源 增加服務器的內存和CPU 2、調整Applicatio…

web3區塊鏈-ETH以太坊

一. 以太坊概述 以太坊(Ethereum)作為區塊鏈技術的代表性項目之一,自2015年發布以來,迅速成為全球區塊鏈行業的核心基礎設施。相比比特幣,以太坊不僅支持點對點的價值轉移,還引入了智能合約,使…

【智能協同云圖庫】智能協同云圖庫第二彈:用戶管理系統后端設計與接口開發

用戶管理系統 一、需求分析 對于用戶模塊,通常要具有下列功能: 二、方案設計 (一)庫表設計 實現用戶模塊的難度不大,在方案設計階段,我們需要確認以下內容: 庫表設計用戶登錄流程如何對用戶權限…

閑庭信步使用SV搭建圖像測試平臺:第十三課——談談SV的數據類型

(本系列只需要modelsim即可完成數字圖像的處理,每個工程都搭建了全自動化的仿真環境,只需要雙擊top_tb.bat文件就可以完成整個的仿真,大大降低了初學者的門檻!!!!如需要該系列的工程…

前端進階之路-從傳統前端到VUE-JS(第一期-VUE-JS環境配置)(Node-JS環境配置)(Node-JS/npm換源)

經過前面的傳統前端開發學習后,我們接下來進行前端的VUE-JS框架學習(寫這篇文章的時候VUE-JS最新版是VUE3,所以默認為VUE3即可) 首先,我們要配置Node-JS環境,雖然我們還不學習Node-JS但是Node-JS可以快速配…

Requests源碼分析:面試考察角度梳理

簡單描述執行流程 ?? Q:能簡單描述一下發送一個requests.get(url)請求時,在requests庫內部的主要執行流程嗎?(從調用get方法到收到響應) 入口委托: get() 方法內部調用 requests.request(GET, url)。Session 接管: request() 方法會獲取或隱式創建一個 Session 對象,并…

航天VR賦能,無人機總測實驗艙開啟高效新篇?

(一)沉浸式培訓體驗? 在傳統的無人機培訓中,操作人員主要通過理論學習和簡單的模擬操作來掌握技能。但這種方式存在很大局限性,難以讓操作人員真正感受無人機在復雜環境下的運行狀態。而航天 VR 技術引入到 VR 無人機總測實驗艙后,徹底改變了…

Kotlin 函數與 Lambda 表達式

今天繼續分享Kotlin學習內容。 目標:掌握函數定義、調用、參數傳遞,以及 Lambda 表達式的基礎用法 1. 函數:Kotlin 的代碼模塊化工具 定義:函數是可重復調用的代碼塊,用于封裝邏輯。 語法: fun 函數名(參…

[mcp-servers] docs | AI客戶端-MCP服務器-AI 架構

鏈接:https://github.com/punkpeye/awesome-mcp-servers 服務器調用 相關專欄:實現Json-Rpc docs:精選MCP服務器資源列表 本專欄為精選 模型上下文協議(MCP)服務器的列表。 MCP 是一種標準協議語言,允許*…

1688商品發布API:自動化上架與信息同步

一、1688商品發布API的核心功能與技術架構 1.1 API功能全景 1688商品發布API是1688開放平臺的核心組件之一,支持商品信息的自動化發布、編輯、上下架及庫存同步。其核心功能包括: 商品信息管理:支持商品標題、描述、價格、庫存、SKU&#…

如何在x86_64 Linux上部署Android Cuttlefish模擬器運行環境

0 軟硬件環境 x86_64服務器Ubuntu20.04 LTS參考:Cuttlefish 虛擬 Android 設備參考: 筆記:搭建 Cuttlefish 運行環境可以下載編好的android-cuttlefish:android-cuttlefish.tar.gz 1 系統采用Ubuntu20.04 LTS 2 搭建cuttlefish…

機器學習9——決策樹

決策樹 Intro 歸納學習(Inductive Learning)的目標:從訓練數據中學習一般規則,應用于未見過的數據。 決策樹是一個樹形結構,其中: 每個分支節點表示一個屬性上的選擇(即決策條件)。…

CppCon 2017 學習:The Asynchronous C++ Parallel Programming Model

清晰理解 Amdahl’s Law(阿姆達爾定律),這是一條描述并行計算加速能力的核心定律。 定義公式: S 1 ( 1 ? P ) P N S \frac{1}{(1 - P) \frac{P}{N}} S(1?P)NP?1? S S S:加速比(Speedup&#xff09…

60頁PPT實戰方案 | 大數據決策分析平臺建設全流程路徑圖

目錄 一、什么是大數據決策分析平臺? 二、為什么要做大數據決策分析平臺建設? 1. 數據已經成為“資源”,但多數組織還停留在“信息孤島” 2. 管理復雜度上升,傳統報表跟不上業務節奏 3. 外部環境不確定性高,倒逼企…

芯谷科技--降壓型DC-DC轉換器D4005

在現代電子設備中,電源管理芯片的性能直接關系到設備的穩定性和效率。D4005以其高效、穩定的性能和廣泛的應用范圍,成為眾多工程師在設計電源方案時的優選。 產品簡介 D4005 是一款高效降壓型 DC-DC 轉換器,具備固定 400KHz 開關頻率&#…

【51單片機節日彩燈控制器設計】2022-6-11

緣由單片機節日彩燈控制器設計-編程語言-CSDN問答 #include "reg52.h" sbit k0P1^2; sbit k1P1^3; sbit k2P1^4; sbit k3P1^5; bit k0,kk0; void main() {unsigned char Xd0;unsigned int ys0; while(1){if(k00&&Xd0){kk0;kP31;while(k00);}if(k10&&…