久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <i id='lnOy8'><tr id='lnOy8'><dt id='lnOy8'><q id='lnOy8'><span id='lnOy8'><b id='lnOy8'><form id='lnOy8'><ins id='lnOy8'></ins><ul id='lnOy8'></ul><sub id='lnOy8'></sub></form><legend id='lnOy8'></legend><bdo id='lnOy8'><pre id='lnOy8'><center id='lnOy8'></center></pre></bdo></b><th id='lnOy8'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='lnOy8'><tfoot id='lnOy8'></tfoot><dl id='lnOy8'><fieldset id='lnOy8'></fieldset></dl></div>

    1. <small id='lnOy8'></small><noframes id='lnOy8'>

      • <bdo id='lnOy8'></bdo><ul id='lnOy8'></ul>
      <legend id='lnOy8'><style id='lnOy8'><dir id='lnOy8'><q id='lnOy8'></q></dir></style></legend>
      <tfoot id='lnOy8'></tfoot>

      Docker Swarm 在 Nginx 中獲取真實(shí) IP(客戶端主機(jī))

      Docker Swarm get real IP (client host) in Nginx(Docker Swarm 在 Nginx 中獲取真實(shí) IP(客戶端主機(jī)))
        <bdo id='5GE3J'></bdo><ul id='5GE3J'></ul>

      • <tfoot id='5GE3J'></tfoot>
          <tbody id='5GE3J'></tbody>

          <i id='5GE3J'><tr id='5GE3J'><dt id='5GE3J'><q id='5GE3J'><span id='5GE3J'><b id='5GE3J'><form id='5GE3J'><ins id='5GE3J'></ins><ul id='5GE3J'></ul><sub id='5GE3J'></sub></form><legend id='5GE3J'></legend><bdo id='5GE3J'><pre id='5GE3J'><center id='5GE3J'></center></pre></bdo></b><th id='5GE3J'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='5GE3J'><tfoot id='5GE3J'></tfoot><dl id='5GE3J'><fieldset id='5GE3J'></fieldset></dl></div>
              <legend id='5GE3J'><style id='5GE3J'><dir id='5GE3J'><q id='5GE3J'></q></dir></style></legend>

                <small id='5GE3J'></small><noframes id='5GE3J'>

                本文介紹了Docker Swarm 在 Nginx 中獲取真實(shí) IP(客戶端主機(jī))的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我有一個(gè)包含 nginx 和 PHP 的堆棧,可以在 Docker Swarm 集群上運(yùn)行.

                I have a stack with nginx and PHP to run on Docker Swarm Cluster.

                在我的 PHP 應(yīng)用程序中,我需要從訪問我的 web 應(yīng)用程序的客戶端主機(jī)獲取包含真實(shí) IP 的 remote_addr ($_SERVER['REMOTE_ADDR']).

                In a moment in my PHP application, I need to get the remote_addr ($_SERVER['REMOTE_ADDR']) which contains the real IP from the client host accessing my webapp.

                但問題是docker swarm集群通知nginx的IP.它顯示了一個(gè)像 10.255.0.2 這樣的內(nèi)部 IP,但真正的 IP 是來自客戶端主機(jī)的外部 IP(如 192.168.101.151).

                But the problem is that the IP informed for nginx by docker swarm cluster. It's showed an Internal IP like 10.255.0.2, but the real IP it's the external IP from the client Host (like 192.168.101.151).

                我該如何解決?

                我的 docker-compose 文件:

                My docker-compose file:

                version: '3'
                
                services:
                  php:
                    image: php:5.6
                    volumes:
                      - /var/www/:/var/www/
                      - ./data/log/php:/var/log/php5
                    networks:
                      - backend
                    deploy:
                      replicas: 1
                  web:
                    image: nginx:latest
                    ports:
                      - "80:80"
                    volumes:
                      - /var/www/:/var/www/
                      - ./data/log/nginx:/var/log/nginx
                    networks:
                      - backend
                networks:
                  backend:
                

                我的 default.conf (vhost.conf) 文件:

                My default.conf (vhost.conf) file:

                server {
                    listen          80;
                    root            /var/www;
                    index           index.html index.htm index.php;
                
                    access_log  /var/log/nginx/access.log  main;
                    error_log   /var/log/nginx/error.log error;
                
                    location / {
                        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;
                
                        try_files   $uri $uri/ /index.php;
                    }
                
                    location = /50x.html {
                        root   /var/www;
                    }
                
                    # set expiration of assets to MAX for caching
                    location ~* .(js|css|gif|png|jp?g|pdf|xml|oga|ogg|m4a|ogv|mp4|m4v|webm|svg|svgz|eot|ttf|otf|woff|ico|webp|appcache|manifest|htc|crx|oex|xpi|safariextz|vcf)(?[0-9]+)?$ {
                            expires max;
                            log_not_found off;
                    }
                
                    location ~ .php$ {
                        try_files                   $uri =404;
                        fastcgi_index               index.php;
                        fastcgi_split_path_info     ^(.+.php)(/.+)$;
                        fastcgi_pass                php:9000;
                        include                     fastcgi_params;
                        fastcgi_param               SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        fastcgi_param               PATH_INFO       $fastcgi_path_info;
                        fastcgi_read_timeout        300;
                    }
                }
                

                我的 nginx 配置文件:

                My nginx config file:

                user  nginx;
                worker_processes    3;
                
                error_log  /var/log/nginx/error.log warn;
                pid        /var/run/nginx.pid;
                
                events {
                    worker_connections  1024;
                }
                
                http {
                    include       /etc/nginx/mime.types;
                    default_type  application/octet-stream;
                
                    keepalive_timeout   15;
                    client_body_buffer_size     100K;
                    client_header_buffer_size   1k;
                    client_max_body_size        8m;
                    large_client_header_buffers 2 1k;
                
                    gzip             on;
                    gzip_comp_level  2;
                    gzip_min_length  1000;
                    gzip_proxied     expired no-cache no-store private auth;
                    gzip_types       text/plain application/x-javascript text/xml text/css application/xml;
                
                    log_format  main  '$remote_addr - $remote_user [$time_local]  "$request_filename" "$request" '
                                      '$status $body_bytes_sent "$http_referer" '
                                      '"$http_user_agent" "$http_x_forwarded_for"';
                
                    access_log  /var/log/nginx/access.log  main;
                
                    sendfile        on;
                    #tcp_nopush     on;
                
                    include /etc/nginx/conf.d/*.conf;
                }
                

                推薦答案

                對于那些不想閱讀所有 github 線程的人 ( https://github.com/moby/moby/issues/25526 ),對我有用的答案是將配置更改為:

                for those don't want to read all the github thread ( https://github.com/moby/moby/issues/25526 ), the answer that was good for me was to change the config to this :

                version: '3.7'
                services:
                  nginx:
                    ports:
                      - mode: host
                        protocol: tcp
                        published: 80
                        target: 80
                      - mode: host
                        protocol: tcp
                        published: 443
                        target: 81
                

                這仍然可以讓內(nèi)部覆蓋網(wǎng)絡(luò)工作,但使用 iptables 的一些技巧將這些端口直接轉(zhuǎn)發(fā)到容器,以便容器內(nèi)的服務(wù)看到數(shù)據(jù)包的正確源 IP 地址.

                This still lets the internal overlay network work, but uses some tricks with iptables to forward those ports directly to the container, so the service inside the container see the correct source IP address of the packets.

                iptables 中沒有允許在多個(gè)容器之間平衡端口的功能,因此您只能將一個(gè)端口分配給一個(gè)容器(其中包括一個(gè)容器的多個(gè)副本).

                There is no facility in iptables to allow balancing of ports between multiple containers, so you can only assign one port to one container (which includes multiple replicas of a container).

                這篇關(guān)于Docker Swarm 在 Nginx 中獲取真實(shí) IP(客戶端主機(jī))的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動(dòng)游標(biāo)不起作用)
                PHP PDO ODBC connection(PHP PDO ODBC 連接)
                Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術(shù)方法)
                php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個(gè)值;等于變量的值)
                MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動(dòng)程序)

                <i id='PvAkt'><tr id='PvAkt'><dt id='PvAkt'><q id='PvAkt'><span id='PvAkt'><b id='PvAkt'><form id='PvAkt'><ins id='PvAkt'></ins><ul id='PvAkt'></ul><sub id='PvAkt'></sub></form><legend id='PvAkt'></legend><bdo id='PvAkt'><pre id='PvAkt'><center id='PvAkt'></center></pre></bdo></b><th id='PvAkt'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='PvAkt'><tfoot id='PvAkt'></tfoot><dl id='PvAkt'><fieldset id='PvAkt'></fieldset></dl></div>

                • <bdo id='PvAkt'></bdo><ul id='PvAkt'></ul>
                    <tbody id='PvAkt'></tbody>

                        <tfoot id='PvAkt'></tfoot><legend id='PvAkt'><style id='PvAkt'><dir id='PvAkt'><q id='PvAkt'></q></dir></style></legend>
                        • <small id='PvAkt'></small><noframes id='PvAkt'>

                        • 主站蜘蛛池模板: 亚洲一区二区三区免费视频 | 日韩高清一区二区 | 久久精品视频在线观看 | 日本免费一区二区三区 | 91成人免费观看 | 国产精品美女 | 国产精品色哟哟网站 | 成人在线免费网站 | 国产一区不卡 | 精品一二三 | 国产不卡在线观看 | 久久久久久久久综合 | 日韩欧美亚洲综合 | 日韩一级精品视频在线观看 | 免费看91 | 91精品国产91久久久久久吃药 | jlzzjlzz国产精品久久 | 亚洲精品成人网 | 91原创视频在线观看 | 91精品国产手机 | 亚洲夜夜爽 | 不卡的av在线 | 久久噜| 欧美中文 | 国产高清视频一区二区 | 欧洲亚洲一区二区三区 | 一区二区三区高清在线观看 | 亚洲午夜av | 久久精品久久久久久 | 亚洲精品免费视频 | 99成人精品 | 国产一区二区在线观看视频 | 欧美亚洲另类丝袜综合网动图 | 国产91精品在线 | 国产精品久久久久久久久久久久 | av片在线观看 | 在线观看黄免费 | 日韩一区二区三区视频在线观看 | 精品国产欧美一区二区三区成人 | 人人人干 | 亚洲 欧美 日韩在线 |