#user nobody; #工作进程,这个可以去修改个数,工作进程主要为master主进程服务的 worker_processes 1; #日志 #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #nginx的端口号 #pid logs/nginx.pid; #配置工作模式和连接数,指令快 events { #在Liunx中是默认使用epoll工作模式 use epoll; #每个worker允许连接的客户端最大连接数 worker_connections 1024; } #http模块的相关配置 http { #include是导入外部文件 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; #tcp_nopush on; #客户端连接超时的时间,也就是客户端连接服务器需要断开,在65秒之内再次访问就不需要从新连接 #keepalive_timeout 0; keepalive_timeout 65; #gzip on; #开启gzip #gzip_min_length 1k; #低于1kb的资源不压缩 #gzip_comp_level 3; #压缩级别【1-9】,越大压缩率越高,同时消耗cpu资源也越多,建议设置在4左右。 #gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css; #需要压缩哪些响应类型的资源,多个空格隔开。不建议压缩图片,下面会讲为什么。 #gzip_disable "MSIE [1-6]\."; #配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持) #gzip_vary on; #是否添加“Vary: Accept-Encoding”响应头 #配置虚拟主机,可以配置多个 server { #虚拟主机监听的端口号 listen 80; #可以定义一个主机IP或localhost或应经备案的域名 server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #路由规则,可以包含很多的表达式 这里的root就是表示根,这里根就是这个nginx.conf配置文件的根目录/usr/local/nginx location / { root html; index 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 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; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
原文:https://www.cnblogs.com/Amywangqing/p/12676692.html