nginx的配置文件(反向代理和主配置)

Posted 夜雨-寄情于曲

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx的配置文件(反向代理和主配置)相关的知识,希望对你有一定的参考价值。

配置文件保存,是为了工作方便。特别是优化好的配置。我们基本可以直接复制粘贴。这样做可以快速的完成手上的工作!!

vim nginx.conf

user nginx;
worker_processes auto;
pid /var/run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
worker_rlimit_nofile 51200;
events {
    worker_connections  51200;
}
http {
    log_format  main  $time_local | $remote_addr | $http_host | $http_x_forwarded_for | $request_method | $request_uri | $server_protocol | $status | $body_bytes_sent | $http_referer | $http_user_agent | $request_time |$upstream_addr | $upstream_status | $upstream_response_time |;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    gzip on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    gzip_proxied        expired no-cache no-store private auth;
    gzip_disable        "MSIE [1-6].";

    server_tokens off;

    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    client_max_body_size 50m;

    include /etc/nginx/conf.d/*.conf;
}

下面是一个反向代理的负载均衡配置文件

upstream  forward02{
    server xxx.xxx.xxx.xxx:8090;
    server xxx.xxx.xxx.xxx:8090;
    }
server {
        listen       8889;
        server_name "";
        access_log  /data/logs/nginx/xxx_access.log  main;
        error_log  /data/logs/nginx/xxx_error.log;
        location / {
             proxy_pass   http://forward02;
             proxy_connect_timeout 600;
             proxy_read_timeout 600;
             proxy_send_timeout 600;
             proxy_redirect off;
             proxy_set_header   Cookie $http_cookie;
             proxy_set_header Host $host;
             proxy_set_header  X-Real-IP $remote_addr;
             proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
       }
}

 

以上是关于nginx的配置文件(反向代理和主配置)的主要内容,如果未能解决你的问题,请参考以下文章

Nginx配置——单域名反向代理多个端口

Nginx架构详解:nginx反向代理配置

nginx反向代理配置

Nginx反向代理2--配置文件配置

linux 安装 nginx 及反向代理配置

Nginx怎么配置反向代理