nginx(二)nginx的配置

2017-11-16  本文已影响18人  yongguang423

nginx官方发布了大量的模块和第三方模块,我们可以通过配置这些模块实现web服务器的绝大部分功能。
先来看个简单的配置文件


#user  nobody;
worker_processes  2;


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 {
    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  120;

    #gzip  on;

    upstream aim3_server{
      server 192.168.1.230:8080;
    }
    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        location ^~/aim3/{
            proxy_pass http://aim3_server;
        }
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

配置项语法

配置项名 配置项值1 配置项值2 … ;
配置项名必须是nginx某模块指定的配置项,配置项名后以空格作为分隔符。配置项的值可以是字符串或数值或者与正则表达式,如果配置项值有多个值则由空格分隔。每一行的配置结束加上分号。
如果配置项值中包括语法符号, 比如空格符, 那么需要使用单引号或双引号括住配置项值。

配置项注释

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

worker_processes

worker_processes 是指nginx 处理请求的进程数量,一般为CPU核心数量。部署nginx时都是使用一个master进程来管理多个work进程,woker进程是真正处理web请求的进程。master进程用来管理woker进程,为管理提供管理服务。


nginx进程关系
上一篇下一篇

猜你喜欢

热点阅读