nginx的简单配置

时间:2019-06-12
本文章向大家介绍nginx的简单配置,主要包括nginx的简单配置使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

        首先,从官网下载 http://nginx.org/  ,之后,查看nginx.conf配置的示例,一下是我的简单配置:

#user  nobody;
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 {
    worker_connections  1024;
}

http {

    #设定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 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,对于普通应用, 
    sendfile        on;
    #tcp_nopush     on;

    #连接超时时间
    #keepalive_timeout  0;
    keepalive_timeout  65;

    #开启gzip压缩
    #gzip  on;
    
    
    #设定负载均衡的服务器列表 支持多组的负载均衡,可以配置多个upstream  来服务于不同的Server.
    #nginx 的 upstream 支持 几 种方式的分配 
    #1)、轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除。 
    #2)、weight 指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。 跟上面样,指定了权重。
    #3)、ip_hash 每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。 
    #4)、fair       
    #5)、url_hash #Urlhash
    #upstream mysvr {
      #weigth参数表示权值,权值越高被分配到的几率越大   
      #1.down 表示单前的server暂时不参与负载
      #2.weight 默认为1.weight越大,负载的权重就越大。     
      #3.backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。  
      #server 192.168.31.233  down;
      #server 192.168.31.233  backup;
      #server 192.168.31.233:8087  weight=1;
      #server 192.168.31.233:8088  weight=2;
    #}

server {
        listen   80;
        server_name  ;

        #access_log  /home/www/wsdt.nczfgjj.com/logs/access_log;
        charset utf-8;
        location / {
                index  index.html index.htm;
                proxy_pass http://ip(填写你的ip):8083/index.html;
                proxy_set_header Host $host;
                proxy_set_header Accept-Encoding "none";
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Via "nginx";
        }

    }
}

原文地址:https://www.cnblogs.com/ztyc/p/11010020.html