亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁(yè)/技術(shù)文章
文章詳情頁(yè)

nginx實(shí)現(xiàn)數(shù)據(jù)庫(kù)端口轉(zhuǎn)發(fā)

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

出于數(shù)據(jù)安全性考慮,正常情況下,網(wǎng)站或者項(xiàng)目的數(shù)據(jù)庫(kù)一般都是禁止外網(wǎng)訪問(wèn),或者只允許部分主機(jī)訪問(wèn)。那么,如何才能不修改這類權(quán)限的前提下,讓其他被禁止訪問(wèn)的主機(jī)也能訪問(wèn)這個(gè)數(shù)據(jù)庫(kù)呢。這時(shí),Nginx的作用就體現(xiàn)出來(lái)了。

1、mysql為例

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

#使用nginx做數(shù)據(jù)庫(kù)端口轉(zhuǎn)發(fā)
stream {
    upstream sql {   
    # 配置數(shù)據(jù)庫(kù)的ip和端口
server 172.16.8.190:3306 weight=1 max_fails=2 fail_timeout=30s;   
    }
    server {
     # 配置本機(jī)暴露端口
       listen     925;
       proxy_connect_timeout 1s;
       proxy_timeout 3s;
       proxy_pass sql;
    }
}

2、完整配置如下

#user ?nobody;#配置用戶或者用戶組,默認(rèn)為nobody
worker_processes ?2;#允許生成的進(jìn)程數(shù),默認(rèn)為1

#制定日志路徑,級(jí)別。這個(gè)設(shè)置可以放入全局塊,http塊,server塊,
#級(jí)別以此為: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進(jìn)程運(yùn)行文件存放地址


events {
? ? worker_connections ?1024; ? ?#最大連接數(shù),默認(rèn)為512
? ? accept_mutex on; ? #設(shè)置網(wǎng)路連接序列化,防止驚群現(xiàn)象發(fā)生,默認(rèn)為on
? ? multi_accept on; ?#設(shè)置一個(gè)進(jìn)程是否同時(shí)接受多個(gè)網(wǎng)絡(luò)連接,默認(rèn)為off
? ? #use epoll; ? ? ?#事件驅(qū)動(dòng)模型,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地址和訪問(wèn)端口
? ? 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; # 編碼設(shè)置
?? ?#開(kāi)啟gzip壓縮
? ? ? ? #gzip模塊設(shè)置
? ? ? ? gzip on; #開(kāi)啟gzip壓縮輸出
? ? ? ? gzip_min_length 1k; #最小壓縮文件大小
? ? ? ? gzip_buffers 4 16k; #壓縮緩沖區(qū)
? ? ? ? gzip_http_version 1.0; #壓縮版本(默認(rèn)1.1,前端如果是squid2.5請(qǐng)使用1.0)
? ? ? ? gzip_comp_level 2; #壓縮等級(jí)
? ? ? ? gzip_types text/plain application/x-javascript text/css application/xml;
? ? ? ? #壓縮類型,默認(rèn)就已經(jīng)包含text/html,所以下面就不用再寫了,寫上去也不會(huì)有問(wèn)題,但是會(huì)有一個(gè)warn。
? ? ? ? gzip_vary on;
? ? ? ? #charset koi8-r;
?? ? ? ?#charset utf-8,gbk; # 避免中文亂碼
? ? ? ? #root ? ?D:/htmlPage/dist;?
? ? ? ? #access_log ?logs/host.access.log ?main;
?? ?location /{
?? ? ? ?#這個(gè)地方指定被訪問(wèn)的文件夾位置
?? ??? ?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;
? ? ? ? }
? ? ?}
?}

到此這篇關(guān)于nginx實(shí)現(xiàn)數(shù)據(jù)庫(kù)端口轉(zhuǎn)發(fā)的文章就介紹到這了,更多相關(guān)nginx 數(shù)據(jù)庫(kù)端口轉(zhuǎn)發(fā)內(nèi)容請(qǐng)搜索以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持!

標(biāo)簽: Nginx
主站蜘蛛池模板: 天堂网ww | 欧美日韩国产在线人成dvd | 黄色毛片视频校园交易 | 国产免费福利片 | 亚洲综合一区二区不卡 | 性激烈的欧美三级高清视频 | 欧美八区 | 狼人综合伊人网 | 精品久久中文字幕 | 亚洲精品福利一区二区三区 | 国产成人一区二区三区视频免费蜜 | 亚洲夜色夜色综合网站 | 在线不卡一区二区三区日韩 | 黄色一级大片网站 | 国产三级视频在线播放 | 毛片1毛片2毛片3毛片4 | 亚洲日韩中文字幕天堂不卡 | 国产色婷婷精品免费视频 | 一级aaaaaa毛片免费 | 欧美成人一级视频 | 1024你懂的国产欧美日韩在 | 99久久综合狠狠综合久久一区 | 日批网站在线观看 | 综合欧美一区二区三区 | 国产欧美日韩不卡在线播放在线 | 最新国产精品自拍 | 成人永久福利免费观看 | 一区二区三区欧美在线 | 最刺激黄a大片免费观看下截 | 黄色大片免费在线观看 | 精品玖玖玖视频在线观看 | 青青国产精品 | 韩国一级毛片大全女教师 | 午夜亚洲精品久久久久 | 亚洲精品免费网站 | 亚洲国产国产综合一区首页 | 女猛烈无遮挡性视频免费 | 国产一区二区免费视频 | 一级a性色生活片毛片 | 毛片视频大全 | 国产精品123区 |