下载地址:http://nginx.org/en/download.html
官方文档:http://nginx.org/en/docs/http/ngx_http_core_module.html
一、nginx目录
conf 配置文件
html 网页文件
logs 日志文件
sbin 主要二进制程序
nginx默认使用80端口启动。
二、nginx配置文件详解
nginx主要配置文件只有一个,就是/conf/nginx.conf
- #user nobody; //nginx用户和组,windows版本不可以指定,例如:user nginx nginx
- //全局区
- worker_processes 1; // 有1个工作的子进程,可以自行修改,但太大无益,因为要争夺CPU,一般设置为 CPU数*核数
- #error_log logs/error.log; //错误日志存放路径
- #error_log logs/error.log notice;
- #error_log logs/error.log info;
- #pid logs/nginx.pid; //pid(进程标识符):存放路径。
- events {
- use epoll; //使用epoll的I/O 模型。linux建议epoll,FreeBSD建议采用kqueue,window下不指定
- // 一般是配置nginx连接的特性
- // 如1个word能同时允许多少连接
- worker_connections 1024; // 这是指 一个子进程最大允许连1024个连接
- keepalive_timeout 60; //keepalive超时时间
- }
- http {//这是配置http服务器的主要段
- include mime.types; //设定mime类型,类型由mime.type文件定义
- default_type application/octet-stream;
- //该段为自定义log输出样式函数。配合下面的access_log使用
- //日志格式设置:
- //$remote_addr与$http_x_forwarded_for用以记录客户端的ip地址;
- //$remote_user:用来记录客户端用户名称;
- //$time_local: 用来记录访问时间与时区;
- //$request: 用来记录请求的url与http协议;
- //$status: 用来记录请求状态;成功是200,
- //$body_bytes_sent :记录发送给客户端文件主体内容大小;
- //$http_referer:用来记录从那个页面链接访问过来的;
- //$http_user_agent:记录客户浏览器的相关信息
- #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- # '$status $body_bytes_sent "$http_referer" '
- # '"$http_user_agent" "$http_x_forwarded_for"';
- //开启log输出。输出位置为logs/access.log(相对于nginx安装根路径) 使用自定的哪个输出格式
- #access_log logs/access.log main;
- sendfile on;
- #tcp_nopush on;
- #keepalive_timeout 0;
- keepalive_timeout 65;
- //是否开启压缩
- #gzip on;
- server {// 这是虚拟主机段
- listen 80;//监控端口
- server_name localhost;//监控域名
- #charset koi8-r;
- #access_log logs/host.access.log main;
- location / {//定位,个人理解就是java中的filter。
- 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;
- # }
- #}
- }
三、详细讲解(点击下面连接跳转到具体详细讲解页面)
1.nginx超详细讲解之概述 2.nginx超详细讲解之server,log 3.nginx超详细讲解之location,rewrite,反向代理及负载均衡 4.nginx超详细讲解之压缩和缓存
*如果有说明毛病和问题请大家提出和指正。