色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

nginx實現數據庫端口轉發

瀏覽:103日期:2023-06-15 15:23:34
目錄
  • 1、mysql為例
  • 2、完整配置如下

出于數據安全性考慮,正常情況下,網站或者項目的數據庫一般都是禁止外網訪問,或者只允許部分主機訪問。那么,如何才能不修改這類權限的前提下,讓其他被禁止訪問的主機也能訪問這個數據庫呢。這時,Nginx的作用就體現出來了。

1、mysql為例

oracle、sqlserver等數據庫配置和下面配置一樣,只是數據庫的端口不一樣而已
需要注意的是這個配置要寫在http外邊

#使用nginx做數據庫端口轉發
stream {
    upstream sql {   
    # 配置數據庫的ip和端口
server 172.16.8.190:3306 weight=1 max_fails=2 fail_timeout=30s;   
    }
    server {
     # 配置本機暴露端口
       listen     925;
       proxy_connect_timeout 1s;
       proxy_timeout 3s;
       proxy_pass sql;
    }
}

2、完整配置如下

#user ?nobody;#配置用戶或者用戶組,默認為nobody
worker_processes ?2;#允許生成的進程數,默認為1

#制定日志路徑,級別。這個設置可以放入全局塊,http塊,server塊,
#級別以此為:debug|info|notice|warn|error|crit|alert|emerg
#error_log ?logs/error.log;
#error_log ?logs/error.log ?notice;
#error_log ?logs/error.log ?info;

#pid ? ? ? ?logs/nginx.pid;#指定nginx進程運行文件存放地址


events {
? ? worker_connections ?1024; ? ?#最大連接數,默認為512
? ? accept_mutex on; ? #設置網路連接序列化,防止驚群現象發生,默認為on
? ? multi_accept on; ?#設置一個進程是否同時接受多個網絡連接,默認為off
? ? #use epoll; ? ? ?#事件驅動模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport
}

stream {
? ? upstream sql { ??
? ? ? ? server 172.16.8.190:3306 weight=1 max_fails=2 fail_timeout=30s; ??
? ? }
? ? server {
? ? ? ?listen ? ? 925;
? ? ? ?proxy_connect_timeout 1s;
? ? ? ?proxy_timeout 3s;
? ? ? ?proxy_pass sql;
? ? }
}

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;

? ? #gzip ?on;

? ? #配置tomcat的IP地址和訪問端口
? ? upstream tomcat {
? ? ? ? server 172.16.8.190:8080;
?? ??? ?
? ? ?}
? ??
? ? server {
? ? ? ? listen ? ? ? 9008;
? ? ? ? server_name ?172.16.8.190;
?? ?#header name含下劃線
?? ?underscores_in_headers on;?
?? ?#charset gbk; # 編碼設置
?? ?#開啟gzip壓縮
? ? ? ? #gzip模塊設置
? ? ? ? gzip on; #開啟gzip壓縮輸出
? ? ? ? gzip_min_length 1k; #最小壓縮文件大小
? ? ? ? gzip_buffers 4 16k; #壓縮緩沖區
? ? ? ? gzip_http_version 1.0; #壓縮版本(默認1.1,前端如果是squid2.5請使用1.0)
? ? ? ? gzip_comp_level 2; #壓縮等級
? ? ? ? gzip_types text/plain application/x-javascript text/css application/xml;
? ? ? ? #壓縮類型,默認就已經包含text/html,所以下面就不用再寫了,寫上去也不會有問題,但是會有一個warn。
? ? ? ? gzip_vary on;
? ? ? ? #charset koi8-r;
?? ? ? ?#charset utf-8,gbk; # 避免中文亂碼
? ? ? ? #root ? ?D:/htmlPage/dist;?
? ? ? ? #access_log ?logs/host.access.log ?main;
?? ?location /{
?? ? ? ?#這個地方指定被訪問的文件夾位置
?? ??? ?root ? D:/htmlPage;
?? ??? ?index ?index.html index.htm;
?? ??? ?#limit_rate 1280k; #限制速度
?? ? ? ?client_max_body_size ?100M;
?? ? ? ?allow all;
?? ??? ?autoindex on;
?? ? ? ?proxy_set_header X-Real-IP ?$remote_addr;
?? ? ? ?proxy_set_header Host $host;
?? ??? ?proxy_set_header X-Real-IP $remote_addr;
?? ??? ?proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
?? ? ? ?add_header "Access-Control-Allow-Headers" "Content-Type";
?? ??? ?add_header "Access-Control-Allow-Methods" "GET";
?? ? ? ?add_header "Access-Control-Allow-Methods" "POST";
?? ? ? ?add_header "Access-Control-Allow-Credentials" "true";
?? ? ? ?add_header "Access-Control-Allow-Origin" "*";
?? ? ? ?proxy_connect_timeout ? ? ? 600s;
?? ??? ?proxy_read_timeout ? ? ? ? ?600s;
?? ??? ?proxy_send_timeout ? ? ? ? ?600s;?
?? ??? ?access_log off;
?? ? ? ?break;
? ? ? ? }
? ? ?}
?}

到此這篇關于nginx實現數據庫端口轉發的文章就介紹到這了,更多相關nginx 數據庫端口轉發內容請搜索以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持!

標簽: Nginx
主站蜘蛛池模板: 国产片一级aaa毛片视频 | 亚洲综合一区二区精品久久 | 一级毛片成人免费看免费不卡 | ffyybb免费福利视频 | 久久精品夜色国产 | 国产国语高清在线视频二区 | 亚洲国产高清人在线 | 美女张开腿男人桶 | 国产不卡在线观看视频 | 欧美日韩国产免费一区二区三区 | 精品成人免费一区二区在线播放 | 美美女下面被cao爽 美女131爽爽爽做爰中文视频 | 亚洲成人影院在线 | 国产精品久久久亚洲 | 国产90后美女露脸在线观看 | 一级片高清 | 91人碰| 日韩永久在线观看免费视频 | 欧美日韩一 | 成人高清毛片a | 国产精品久久久精品视频 | 日韩欧美特级毛片 | 日黄网站 | 国产毛片a精品毛 | 国产专区一va亚洲v天堂 | 日韩特级黄色片 | 特级毛片aaa免费版 特级毛片a级毛免费播放 | 欧美一级日韩一级亚洲一级 | 欧美色视频日本片高清在线观看 | 久久免费看视频 | 日韩精品中文字幕一区二区三区 | 成人亚洲在线 | 一区二区三区国产 | 国产成人v视频在线观看 | 久久a热6 | 亚洲精品成人一区二区www | 99热在线获取最新地址 | 中文字幕有码在线播放 | 性做久久久久久久免费看 | 成人国产精品一区二区网站 | 啪视 |