• Nginx反向代理


    Nginx反向代理

    环境

    代理服务器 192.168.133.161

    web服务 192.168.133.160

    代理端:

    # vim /etc/nginx/nginx.conf
    worker_processes  1;
    error_log  logs/error.log;
    worker_rlimit_nofile 102400;
    pid        /var/run/nginx.pid;
    events {
        worker_connections  10240;
        use epoll;
    }
    
    http {
        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  /var/log/nginx/access.log  main;
        sendfile          on;
        tcp_nopush        on;
        tcp_nodelay       on;
        gzip              on;
        keepalive_timeout  65;
        types_hash_max_size 2048;
        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;
        include /etc/nginx/conf.d/*.conf;
     }
    
    # 代理服务器指向www.lisi.com(192.168.133.160:8080)
    [root@nginx-proxy conf.d]# cat proxy.conf
    server {
            listen 80;
            server_name www.proxy.com;
            root /usr/share/nginx/html;
            # Load configuration files for the default server block.
            # include /etc/nginx/default.d/*.conf;
            location / {
                    proxy_pass http://192.168.133.160:8080;
                    proxy_set_header Host $http_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 X-NginX-Proxy true;
                    proxy_connect_timeout 30;
                    proxy_send_timeout 60;
                    proxy_read_timeout 60;
                    proxy_buffering on;
                    proxy_buffer_size 32k;
                    proxy_buffers 4 128k;
                    proxy_busy_buffers_size 256k;
                    proxy_max_temp_file_size 256k;
            }
            error_page 404 /404.html;
            location = /40x.html {
            }
            error_page 500 502 503 504 /50x.html;
            location = /50x.html {
            }
    }
    
    # 代理服务器指向www.wangwu.com(192.168.133.160:80)
    [root@nginx-proxy conf.d]# cat proxy-test.conf
    server {
            listen 80;
            server_name www.proxy-test.com;
            root /usr/share/nginx/html;
            # Load configuration files for the default server block.
            # include /etc/nginx/default.d/*.conf;
            location / {
                    proxy_pass http://192.168.133.160:80;
                    proxy_set_header Host $http_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 X-NginX-Proxy true;
                    proxy_connect_timeout 30;
                    proxy_send_timeout 60;
                    proxy_read_timeout 60;
                    proxy_buffering on;
                    proxy_buffer_size 32k;
                    proxy_buffers 4 128k;
                    proxy_busy_buffers_size 256k;
                    proxy_max_temp_file_size 256k;
            }
            error_page 404 /404.html;
            location = /40x.html {
            }
            error_page 500 502 503 504 /50x.html;
            location = /50x.html {
            }
    }
    
    

    服务端

    [root@nginx-server conf.d]# cat lisi-query.conf
    server {
            listen 8080;
            server_name www.lisi.com;
            access_log /var/log/nginx/lisi-access.log main;
            error_log /var/log/nginx/lisi-error.log;
            set_real_ip_from 192.168.133.161;
            location /{
                    root /var/www/lisi;
                    index index.html index.htm index.php;
                    deny 192.168.133.5;
                    allow all;
    
            }
    
            location /status{
            stub_status on;
            access_log off;
            }
    }
    
    
    [root@nginx-server conf.d]# cat proxy.conf
    server {
            listen 192.168.133.160:80;
            server_name www.wangwu.com;
            access_log /var/log/nginx/wangwu-access.log main;
            error_log /var/log/nginx/wangwu-error.log;
            set_real_ip_from 192.168.133.161;
            location /{
                    root /var/www/test;
                    index index.html index.htm index.php;
    
            }
            location /status{
            stub_status on;
            access_log off;
            }
    }
    
    
    配置若有遗漏或错误,请评论留言。
  • 相关阅读:
    BZOJ2337 [HNOI2011]XOR和路径
    「学习笔记」3.31代码学习
    uva live 12846 A Daisy Puzzle Game
    Cannot use ImageField because Pillow is not installed
    Android点击Button水波纹效果
    hdu 1241 Oil Deposits
    c++ 字符输入读取
    clutter recoder
    C/C++获取数组长度
    vector array and normal stanard array
  • 原文地址:https://www.cnblogs.com/BrokenEaves/p/15152584.html
Copyright © 2020-2023  润新知