Nginx反向代理配置

mtain 2016年04月28日 227次浏览

**Nginx版本:**nginx-1.8.1.tar.gz

配置文件:
默认放置位置/usr/local/nginx/conf/nginx.conf

user root;
worker_processes 1;

error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;

pid logs/nginx.pid;

events {
use epoll;
worker_connections 1024;
}

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;

server {
  listen       8080;
  server_name  139.196.242.225;

  charset gb2312;
  
  #charset utf8;
  #charset koi8-r;
  #access_log  logs/host.access.log  main;
  location / {
    proxy_pass  http://需要代理的IP:9980;

    #Proxy Settings
    proxy_redirect     off;
    proxy\_set\_header   Host             $host:$server_port;
    proxy\_set\_header   X-Real-IP        $remote_addr;
    proxy\_set\_header   X-Forwarded-For  $proxy\_add\_x\_forwarded\_for;
    proxy\_next\_upstream error timeout invalid\_header http\_500 http\_502 http\_503 http_504;
    proxy\_max\_temp\_file\_size 0;
    proxy\_connect\_timeout      90;
    proxy\_send\_timeout         90;
    proxy\_read\_timeout         90;
    proxy\_buffer\_size          4k;
    proxy_buffers              4 32k;
    proxy\_busy\_buffers_size    64k;
    proxy\_temp\_file\_write\_size 64k;
  }
  #error_page  404			  /404.html;
  # redirect server error pages to the static page /50x.html
  }

}

相关问题

  1. 编码问题:如果要代理的项目编码为gb2312,为了保持一致,可设置charset gb2312;
  2. 反向代理非80端口问题:反向代理非80端口时,如果出现地址跳转端口被去掉,可配置proxy_set_header Host $host:$server_port;
  3. 反向代理未出现session等登陆权限问题