nginx配置文件

  1. /etc/nginx/nginx.conf
    1)main位于配置文件的最高层
    2)mian层下可以有event层、http层
    3)http层下面允许有多个server层、用于对不同的网站做不同的配置
    4)server层下面允许有多个location,用于对不同路径做不同的配置
[root@web01 ~]# cat /etc/nginx/nginx.conf 

user  nginx;         运行nginx的用户
worker_processes  1;      一个worker运行的进程数量(数值和cpu核数个数一致)

error_log  /var/log/nginx/error.log warn;      错误日志路径
pid        /var/run/nginx.pid;          存放nginx运行进程的pid文件路径

事件模块
events {
    worker_connections  1024;     每个work进程支持的最大连接数
}

非虚拟主机的配置或公共配置定义在http{}段内, server{}段外
http {
    include       /etc/nginx/mime.types;        加载这个路径的配置文件(mime.type对应请求的application—type)
    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  /var/log/nginx/access.log  main;   日志存放路径

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;      连接超时时间

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;     包含这个路径下的配置文件
}

  1. /etc/nginx/conf.d/*.conf 虚拟主机配置文件
[root@web01 ~]# cat /etc/nginx/conf.d/default.conf 
server {
    listen       80;           网站访问端口
    server_name  localhost;      访问域名

    #charset koi8-r;            字符编码
    #access_log  /var/log/nginx/host.access.log  main;     日志存放路径(main指的是前面定义的日志格式)

    location / {      指的是访问域名下/就返回/usr/share/nginx/html/index.html
        root   /usr/share/nginx/html;
        index  index.html index.htm;  如果找不到index.html,就返回index.htm
    }

    #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   /usr/share/nginx/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;
    #}
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容