Nginx的安装和配置文件详细说明

1.nginx的安装

1.1解压nginx文件

Nginx的安装和配置文件详细说明

1.2 nginx文件说明

Nginx的安装和配置文件详细说明

3.启动nginx

Nginx的安装和配置文件详细说明

4.验证是否启动成功

Nginx的安装和配置文件详细说明

2 配置文件(说明)

user  nginx;nginx的运行账号(rpm安装时会自动创建这个账号),也可以写成user nginx nginx表示用户和组

worker_processes  10;工作进程数(worker),一般等于cpu内核数或者两倍

worker_rlimit_nofile 100000;文件描述符数量

error_log   /var/log/nginx/error.log;

#error_log  /var/log/nginx/error.log  notice;

#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;

events {

    worker_connections  1024;每个worker进程允许的连接数

    use epoll;网络I/O事件模型,linux推荐用epoll,FreeBSD推荐用kqueue

}

http {

    include       /etc/nginx/mime.types;include用来引用其他的配置文件,即可以按照需求将不同的配置写到不同的文件里面

    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"';

定义日志格式,格式名字设为main

    access_log  /var/log/nginx/access.log  main;

access日志文件的路径,采用上面定义的main 格式记录

    sendfile        on;

    tcp_nopush      on;

    tcp_nodelay     on;

    server_tokens   off;

    gzip            on;启用压缩

    gzip_static     on;启用HTTPGzipStatic模块(不在corestandard模块组中,rpm安装带了此模块)

    gzip_comp_level 5;压缩级别,1最小最快,9最大最慢

    gzip_min_length 1024;压缩的最小长度,小于此长度的不压缩(此长度即header中的Content-Length)

    keepalive_timeout  65;

    limit_zone   myzone  $binary_remote_addr  10m;

    # Load config files from the /etc/nginx/conf.d directory

    include /etc/nginx/conf.d/*.conf;

    server {

        limit_conn   myzone  10;

        listen       80;端口

        server_name  _;域名

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

            root   /usr/share/nginx/html;主目录

            index  index.html index.htm;

        }

………………