欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Nginx實(shí)現(xiàn)端口映射的示例代碼

 更新時(shí)間:2025年09月17日 11:19:32   作者:IT農(nóng)民工~  
本文主要介紹了Nginx實(shí)現(xiàn)端口映射的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

1. 找到nginx的部署路徑

[root@SH-DB-02 adi]# ps -ef | grep nginx
root      53617      1  0  2019 ?        00:00:07 nginx: master process ./nginx
nobody   176294  53617  0 12:31 ?        00:00:01 nginx: worker process
[root@SH-DB-02 adi]# 
[root@SH-DB-02 adi]# 
[root@SH-DB-02 adi]# 
[root@SH-DB-02 adi]# ls -la /proc/53617/exe
lrwxrwxrwx 1 root root 0 6月  20 14:01 /proc/53617/exe -> /opt/nginx/webserver/nginx/sbin/nginx

最終找到的nginx的路徑為“ /opt/nginx/webserver/nginx/sbin/nginx”

2. 備份原來的配置文件

cd /opt/nginx/webserver/nginx/conf/
cp nginx.conf nginx20250620.txt

3. 編輯nginx.conf文件

nano nginx.conf

4. 在http塊中添加新的server配置

在現(xiàn)有的server塊(8080端口那個(gè))后面,在http塊的最后一個(gè) } 之前添加:

server {
    listen       8083;
    server_name  本機(jī)IP;
    
    # 只代理特定路徑
    location /xizangott/C2callback {
        proxy_pass http://127.0.0.1:8081;
        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;
        
        # 設(shè)置超時(shí)時(shí)間
        proxy_connect_timeout 60s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;
    }
    
    # 其他請(qǐng)求返回404
    location / {
        return 404;
    }
}

5. 完整的nginx.conf應(yīng)該是這樣的:

user  nobody;
worker_processes  8;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log  logs/error.log  info;
pid        logs/nginx.pid;
worker_rlimit_nofile  51200;
events {
    use epoll;
    worker_connections  51200;
}
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"';
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                '$status $body_bytes_sent "$http_referer" '
                '"$http_user_agent" $http_x_forwarded_for "$request_time"';
    access_log  logs/access.log main;
    sendfile        on;
    tcp_nopush     on;
    keepalive_timeout  65;
    autoindex_exact_size off;
    autoindex_localtime on;
    autoindex on;
    gzip  on;
server {
listen       8080;
server_name  本機(jī)IP;
index index.html index.htm;
root /data/pic;
autoindex off;
if (-d $request_filename)
{
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}
location /ngx_status {
        stub_status     on;
        access_log      off;
        allow   127.0.0.1 ;
        deny  all;
        }
}

server {
    listen       8083;
    server_name  本機(jī)IP;
    
    # 只代理特定路徑
    location /xizangott/C2callback {
        proxy_pass http://127.0.0.1:8081;
        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;
        
        # 設(shè)置超時(shí)時(shí)間
        proxy_connect_timeout 60s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;
    }
    
    # 其他請(qǐng)求返回404
    location / {
        return 404;
    }
}
}

6. 保存文件并退出nano

按 Ctrl + X,然后按 Y,最后按 Enter

7. 測(cè)試配置文件語法

cd /opt/nginx/webserver/nginx/sbin/
./nginx -t

8. 重新加載nginx配置

./nginx -s reload

9. 驗(yàn)證配置是否生效

# 檢查8083端口是否在監(jiān)聽
netstat -tulpn | grep :8083

# 檢查nginx進(jìn)程
ps -ef | grep nginx

10. 測(cè)試代理功能

# 測(cè)試目標(biāo)路徑
curl -I http://本機(jī)ip:8083/xizangott/C2callback

# 測(cè)試其他路徑(應(yīng)該返回404)
curl -I http://本機(jī)ip:8083/test

11. 查看日志(如果有問題)

# 查看錯(cuò)誤日志
tail -f /opt/nginx/webserver/nginx/logs/error.log

# 查看訪問日志
tail -f /opt/nginx/webserver/nginx/logs/access.log

按照以上步驟操作即可。配置完成后,訪問 http://本機(jī)IP:8083/xizangott/C2callback 就會(huì)被代理到你的8081端口的Java應(yīng)用了。
這樣訪問http://本機(jī)ip:8083/xizangott/C2callback會(huì)映射到“http://本機(jī)ip:8081/xizangott/C2callback”

到此這篇關(guān)于Nginx實(shí)現(xiàn)端口映射的示例代碼的文章就介紹到這了,更多相關(guān)Nginx 端口映射內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Nginx啟用Brotli算法壓縮的示例

    Nginx啟用Brotli算法壓縮的示例

    這篇文章主要介紹了Nginx啟用Brotli算法壓縮的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-03-03
  • 在nginx中部署https服務(wù)的詳細(xì)步驟

    在nginx中部署https服務(wù)的詳細(xì)步驟

    Web服務(wù)器一般指網(wǎng)站服務(wù)器,可以處理瀏覽器等Web客戶端的請(qǐng)求并返回相應(yīng)響應(yīng),也可以放置網(wǎng)站文件,讓全世界瀏覽;可以放置數(shù)據(jù)文件,讓全世界下載,本文主要介紹nginx中部署https服務(wù)的具體流程,也是搭建web的開端與主要步驟之一
    2023-10-10
  • Nginx啟用proxy_cache緩存的方法

    Nginx啟用proxy_cache緩存的方法

    本篇文章主要介紹了Nginx啟用proxy_cache緩存的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-03-03
  • Nginx 禁用靜態(tài)文件緩存的配置方法

    Nginx 禁用靜態(tài)文件緩存的配置方法

    禁用緩存可能會(huì)導(dǎo)致性能下降,因?yàn)槊看握?qǐng)求都需要從后端服務(wù)器獲取文件,因此,你需要根據(jù)具體情況權(quán)衡利弊并做出決策,這篇文章給大家介紹Nginx 禁用靜態(tài)文件緩存的方法,感興趣的朋友一起看看吧
    2024-02-02
  • nginx php-fpm中啟用慢日志配置(用于檢測(cè)執(zhí)行較慢的PHP腳本)

    nginx php-fpm中啟用慢日志配置(用于檢測(cè)執(zhí)行較慢的PHP腳本)

    這篇文章主要介紹了nginx php-fpm中啟用慢日志配置,php-fpm慢日志slowlog設(shè)置可以讓我們很好的看見哪些php進(jìn)程速度太慢而導(dǎo)致的網(wǎng)站問題,可以讓我們方便的找到問題的所在,需要的朋友可以參考下
    2014-05-05
  • 實(shí)現(xiàn)Nginx中使用PHP-FPM時(shí)記錄PHP錯(cuò)誤日志的配置方法

    實(shí)現(xiàn)Nginx中使用PHP-FPM時(shí)記錄PHP錯(cuò)誤日志的配置方法

    最近在本地搭建的LNMP的開發(fā)環(huán)境。為了開發(fā)的時(shí)候不影響前端的正常開發(fā)就屏蔽的PHP里面php.ini中的一些錯(cuò)誤提示。但是這樣一來,就影響到了后端開發(fā)的一些問題比如不能及時(shí)調(diào)試開發(fā)中的一些問題
    2014-05-05
  • Nginx反向代理的location路徑映射方式

    Nginx反向代理的location路徑映射方式

    這篇文章主要介紹了Nginx反向代理的location路徑映射方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • Nginx配置同時(shí)支持http和https的兩種方式

    Nginx配置同時(shí)支持http和https的兩種方式

    現(xiàn)在的網(wǎng)站支持Https幾乎是標(biāo)配功能,Nginx能很好的支持Https功能,本文主要介紹了Nginx配置同時(shí)支持http和https的兩種方式,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-03-03
  • Nginx在Windows下的安裝與使用過程詳解

    Nginx在Windows下的安裝與使用過程詳解

    Nginx (engine x) 是一個(gè)高性能的HTTP和反向代理服務(wù)器,也是一個(gè)IMAP/POP3/SMTP服務(wù)器,這篇文章主要介紹了Nginx在Windows下的安裝與使用,需要的朋友可以參考下
    2023-05-05
  • nginx加php-fpm出現(xiàn)502 bad gateway錯(cuò)誤的5種解決方法

    nginx加php-fpm出現(xiàn)502 bad gateway錯(cuò)誤的5種解決方法

    這篇文章主要介紹了nginx加php-fpm環(huán)境中出現(xiàn)502 bad gateway錯(cuò)誤的5種解決方法,總結(jié)歸納服務(wù)器出現(xiàn)502錯(cuò)誤的原因多數(shù)為連接過多和腳本超時(shí),本文總結(jié)了5種解決方法,需要的朋友可以參考下
    2014-05-05

最新評(píng)論