#user nobody; #工作的进程数 这个数字的设计 一般跟CPU有关 4核8线程 那么这里就写成8 worker_processes 1; #错误日志存放的地方 #error_log logs/error.log; #错误日志存放的地方 还有就是错误日志打印的格式 notice #error_log logs/error.log notice; #错误日志存放的地方 还有就是错误日志的 格式info的这种格式 #error_log logs/error.log info; #进程号 是为了系统的重启 重启是先杀死进程 然后启动 #pid logs/nginx.pid; events { #工作的线程数 这个数字 一般情况下就是 worker_processes x 1024 worker_connections 1024; } #这里表示的是HTTP的配置 http { #这里使用的是mime.types这种数据类型 include mime.types; #默认使用的是8进制进行传输 default_type application/octet-stream; #定义了一个日志格式 这个日志格式 的名字叫做 main 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; #nginx默认是支持 keepalived也是用来做高可用的,解决单点问题的,防止单机nginx意外死亡 #keepalive_timeout 0; #默认和KeepAlived通信的超时时间 keepalive_timeout 65; #发送数据的时候 默认使用 gzip进行压缩 #gzip on; #配置负载均衡 upstream ff1 { ip_hash; server 106.54.13.167:8080; server 112.124.19.18:8080; } server { listen 9999; server_name localhost; #配置了动态资源的请求 location / { proxy_pass http://112.124.19.18:8080; } #匹配的是静态资源的请求 location ~* \.(jpg|js|css|html)$ { root /usr/local/webapp; expires 1d; } } server { listen 8989; server_name localhost; #如果你访问的是 :8989/ff.html那么就去 根目录下 ff文件夹中找ff.html这个文件 location /ff.html { root ff; } #如果你请求的资源的后缀是 .jpg的话 那么就要自动的转换到一个Tomcat服务器上去 location ~ \.jpg$ { #配置的是反向代理 #proxy_pass http://localhost:8080; # #配置负载均衡 proxy_pass http://bobo1; } } #虚拟主机的地方 server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #如果你访问的是 / 那么就直接访问 根目录下的 html文件夹中的index.html或者index.ht # m location / { root html; index index.html index.htm; } # 如果请求产生了404 那么 就要跳转到 404.html页面 error_page 404 /404.html; #这个表示的是 如果请求的是 404.html 那么就去跟目录下的bobo文件夹中找 404.html文 #件 location = /404.html { root bobo; } # redirect server error pages to the static page /50x.html # 这个表示的是 如果请求的资源之后 返回的是 50开头的异常 那么 默认去访问50x.html #页面 error_page 500 502 503 504 /50x.html; #如果你请求的是是 50x.html那么应该去 根目录下的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; # } #} }