启动命令:

-c 参数,指定nginx配置文件

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

停止命令

/usr/local/nginx/sbin/nginx -s stop

重启命令

/usr/local/nginx/sbin/nginx -s reload

查看nginx其它命令

/usr/local/nginx/sbin/nginx -h

 

nginx.conf的具体配置可参考 http://wiki.nginx.org

以下是一个典型的配置:

user  nobody nobody;
worker_processes  16;
worker_rlimit_nofile 655350;

pid        /var/run/nginx.pid;

events {
    #use kqueue;
    use epoll;
    worker_connections  20000;
    #multi_accept on;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    ## TCP options 
    tcp_nopush		on;
    tcp_nodelay		on;

    ## Timeouts 
    client_body_timeout   10;
    client_header_timeout 10;
    keepalive_timeout	15 15;
    #send_timeout	30;

    ## General Options
    ignore_invalid_headers   on;
    recursive_error_pages    on;
    sendfile			on;
    server_name_in_redirect off;
    server_tokens           off;
    client_max_body_size	64m;
    client_body_buffer_size    256k;

    include inc/*.conf;

    server {
        listen       8360;
        server_name  localhost;

        #location /NginxStatus {
        location /nginx_status {
                stub_status on;
                access_log off;
        }

        location /fpm_status {
                if ( $arg_sid = '' ) {
                        rewrite ^ /fpm_list last;
                }
                include fastcgi_params;
                fastcgi_pass unix:/var/run/$arg_sid/fpm.sock;
        }

        #列出所有正在运行的fpm-sock
        location /fpm_list {
                default_type text/html;
                content_by_lua "
                        ngx.print('<h2>Runing FPM instances:</h2>')
                        local cmd = [[/bin/ls -1 /var/run/ | grep rgapp- | awk '{print \"<p><a href=?sid=\"$1\">\"$1\"</a>\"}']]
                        local f = io.popen(cmd, 'r')
                        local log = f:read('*a')
                        f:close()
                        ngx.print(log)
                ";
        }

        location / {
		return 403;
        }
    }
 
    include include/*.conf;

}

  

一般来说,我们可以使用一个链接文件,将conf目录指向一个特定目录,以方便管理。

例如,笔者所在的公司喜欢将所有的服务器配置文件集中在/home/server_config中,然后在该目录中新建一个子目录 nginx,再将/usr/local/nginx/conf通过链接文件指向/home/server_config/nginx。