您的位置:首页 > 运维架构 > Nginx

Ngin的配置文件nginx.conf完整配置说明(包括fastcgi和负载均衡设置)

2015-09-05 10:51 826 查看
#用户 用户组

user www www;
#工作进程,根据硬件调整,有人说几核cpu,就配几个,我觉得可以多一点

worker_processes 4;
#错误日志

error_log logs/error.log;
#pid文件位置

pid logs/nginx.pid;
worker_rlimit_nofile 8192;
events {#工作进程的最大连接数量,根据硬件调整,和前面工作进程配合起来用,尽量大,但是别把cpu跑到很高就行worker_connections 1024;}http {include conf/mime.types;#反向代理配置,可以打开proxy.conf看看include /etc/nginx/proxy.conf;#fastcgi配置,可以打开fastcgi.conf看看include /etc/nginx/fastcgi.conf;default_type application/octet-stream;#日志的格式log_format main ‘$remote_addr – $remote_user [$time_local] $status ‘‘”$request” $body_bytes_sent “$http_referer” ‘‘”$http_user_agent” “$http_x_forwarded_for”’;#访问日志access_log logs/access.log main;sendfile on;tcp_nopush on;#根据实际情况调整,如果server很多,就调大一点server_names_hash_bucket_size 128; # this seems to be required for some vhosts#这个例子是fastcgi的例子,如果用fastcgi就要仔细看server {   # php/fastcgilisten 80;#域名,可以有多个server_name   domain1.com   www.domain1.com;(两个)#访问日志,和上面的级别不一样,应该是下级的覆盖上级的access_log logs/domain1.access.log main;root html;location / {    index index.html index.htm index.php;}#所有php后缀的,都通过fastcgi发送到1025端口上#上面include的fastcgi.conf在此应该是有作用,如果你不include,那么就把fastcgi.conf的配置项放在这个下面。location ~ .php$ {       fastcgi_pass 127.0.0.1:1025;}}#这个是反向代理的例子server {           #simple reverse-proxylisten 80;server_name domain2.com www.domain2.com;access_log logs/domain2.access.log main;#静态文件,nginx自己处理location ~ ^/(images|javascript|js|css|flash|media|static)/ {      root /var/www/virtual/big.server.com/htdocs;      #过期30天,静态文件不怎么更新,过期可以设大一点,如果频繁更新,则可以设置得小一点。      expires 30d;}#把请求转发给后台web服务器,反向代理和fastcgi的区别是,反向代理后面是web服务器,fastcgi后台是fasstcgi监听进程,当然,协议也不一样。location / {      proxy_pass http://127.0.0.1:8080; }}#upstream的负载均衡,weight是权重,可以根据机器配置定义权重。据说nginx可以根据后台响应时间调整。后台需要多个web服务器。
01
upstream
big_server_com {
02
   server 127.0.0.3:8000 weight=5;
03
   server 127.0.0.3:8001 weight=5;
04
   server 192.168.0.1:8000;
05   
server 192.168.0.1:8001;
06
07
 
 
08
server {
09
   listen 80;
10
   server_name big.server.com;
11
   access_log logs/big.server.access.log main; 
12
 
 
13    
location / {
14      
proxy_pass http:
//big_server_com;
15
    }
16
}
17
}
—————————————–Nginx 安置后只有一个法式文件,自己并不供给各类办理法式,它是利用参数和体系旌旗灯号机制对 Nginx 历程自己举行节制的。 Nginx 的参数包罗有如下几个:-c :利用指定的设置装备摆设文件而不是 conf 目次下的 nginx.conf 。-t:测试设置装备摆设文件是否准确,在运行时必要从头加载设置装备摆设的时辰,此号令很是主要,用来检测所点窜的设置装备摆设文件是否有语法错误。-v:表现 nginx 版本号。-V:表现 nginx 的版本号以及编译情况信息以及编译时的参数。比方我们要测试某个设置装备摆设文件是否誊写准确,我们可以利用以下号令
sbin/nginx – t – c conf/nginx2.conf

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: