nginx主配置文件详解

文章来源:《nginx从入门到精通》作者:凉白开,漠北

nginx主配置文件nginx.conf配置详解:

vim nginx.conf

user nobody nobody; #运行nginx的所属组和所有者

worker-processes 2;   #开启两个nginx工作进程,一般几个CPU核心写几

error_log logs/error.log  notice; #错误日志路径

pid logs/nginx.pid; #pid路径

events {

        worker_connections 1024; #一个进程能同时处理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;

keepalive_timeout 65;       #keepalive超时时间

#开始配置一个域名,一个server配置段一般对应一个域名

server {

     listen    80;    在本机所有ip上监听80,也可写为ip:80,这样只会监听ip上的80 端口

    server_name     www.test.com;     #域名

     root    /www/html/www.test.com;    #站点根目录(程序目录)

     index  index.html  index.html;      #索引文件

     location  /  {         #可以设置多个location

            root     /var/html/www.test.com;        #站点根目录(程序目录)

                     }

   error_page     500   502   503  504   /50x.html;           #定义错误页面,如果是500错误,则把站点根目录下的50x.html返回给客户

     location = /50x.html   {

         root            /www/html/www.test.com;

                                     }

}

}

原文地址:https://www.cnblogs.com/xinxiao/p/8260093.html