#user nobody; #启动进程数,即启动ngnix服务的个数,一般设置和cpu的数量相等 worker_processes 1; #全局错误日志及PID文件 #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #nginx进程ID #pid logs/nginx.pid; events { #单个后台worker process进程的最大并发连接数 # 并发总数是 worker_processes 和 worker_connections 的乘积 # 即 max_clients = worker_processes * worker_connections worker_connections 1024; } http { #设定mime类型,类型由mime.type文件定义 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 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件, #功能是优化文件拷贝,提升web sever性能 #对于普通应用,必须设为 on, #若是用来进行下载等应用磁盘IO重负载应用,可设置为 off, #以平衡磁盘与网络I/O处理速度,下降系统的uptime. sendfile on; #tcp_nopush on; #keepalive 维持http链接时间 #keepalive_timeout 0; keepalive_timeout 65; #默认状况下,gzip压缩是关闭的,该功能是面向客户端的, gzip压缩功能是减小带宽,但会增长服务器CPU的开销,Nginx默认只对text/html进行压缩 ,若是要对html以外的内容进行压缩传输,咱们须要手动来调。 #gzip on; #配置虚拟主机 server { #虚拟主机端口 listen 8098; #虚拟主机域名 server_name localhost; #字符编码 #charset koi8-r; #访问日志 #access_log logs/host.access.log main; #代理 location / { root source/electric; index index.html index.htm; proxy_pass http://myapp; #代理地址,指向上面的myapp } #404错误提示页 #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; } ########如下是配置php代理############ # 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; #} } #一个ngxin能够配置多个虚拟主机,配置同上 # 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############## # 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; # } #} }