Nginx的配置与启动

配置文件

$ cat conf/nginx.conf

#设置用户
user  nginx;

#工作线程
worker_processes  auto;
#error_log  logs/error.log;
#设置日志级别
error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#编译时文件安装的目录
pid        /var/run/nginx.pid;
#打开最大的文件描述符
worker_rlimit_nofile 65535;

events {
	#设置工作模式
    use epoll;
	#设置最大连接数
    worker_connections  65535;
}


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" $scheme  $request_filename $args';

    access_log  logs/access.log  main;
    
    server_tokens off;
    
    sendfile        on;
    #防止网络阻塞
    tcp_nopush     on;
    
    #keepalive_timeout  0;
    keepalive_timeout  65;


    #优化相关的配置
    server_names_hash_bucket_size 128;
    client_max_body_size 20m;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    
    #打开压缩
    gzip  on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    
    #虚拟主机的开始
    server {
       #指定监听端口
        listen       80;
       #指定ip或者域名
        server_name  localhost 10.50.34.88;
       #指定字体 
        #charset koi8-r;
        charset utf-8;
        #指定虚拟主机日志
        access_log  logs/host.access.log  main;
    	#设置访问根时的回应
        location / {
            #设置工作目录
            root   html;
            #设置主页
            index  index.html index.htm;
        }
        #设置404时的页面            /404.html指的是工作目录下的404.html
        error_page  404              /404.html;
    
        #redirect server error pages to the static page /50x.html
        
        #指定5系列状态码时跳转页面
        error_page   500 502 503 504  /50x.html;
        #设置当访问/50x.html时的操作
        location = /50x.html {
            #设置当前的工作目录
            root   html;
        }
    }
}

测试配置文件

$ sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

启动

sbin/nginx

测试

posted @ 2023-12-18 15:20  厚礼蝎  阅读(34)  评论(0编辑  收藏  举报