nginx配置
2015-10-10 17:59
549 查看
研究这个东西好多天了...没人教,难啊...什么都得一个一个搜索。Fuck
来源v
51cto
http://blog.s135.com/tags/nginx/
中文文档:http://wiki.nginx.org/NginxChs
#用户用户组 userwwwwww; #工作进程,根据硬件调整,有人说几核cpu,就配几个,我觉得可以多一点 worker_processes5; #错误日志 error_loglogs/error.log; #pid文件位置 pidlogs/nginx.pid; worker_rlimit_nofile8192;
events{
#工作进程的最大连接数量,根据硬件调整,和前面工作进程配合起来用,尽量大,但是别把cpu跑到100%就行
worker_connections4096;
}
http{
includeconf/mime.types;
#反向代理配置,可以打开proxy.conf看看
include/etc/nginx/proxy.conf;
#fastcgi配置,可以打开fastcgi.conf看看
include/etc/nginx/fastcgi.conf;
default_typeapplication/octet-stream;
#日志的格式
log_formatmain‘$remote_addr–$remote_user[$time_local]$status‘
‘”$request”$body_bytes_sent“$http_referer”‘
‘”$http_user_agent”“$http_x_forwarded_for”’;
#访问日志
access_loglogs/access.logmain;
sendfileon;
tcp_nopushon;
#根据实际情况调整,如果server很多,就调大一点
server_names_hash_bucket_size128;#thisseemstoberequiredforsomevhosts
#这个例子是fastcgi的例子,如果用fastcgi就要仔细看
server{#php/fastcgi
listen80;
#域名,可以有多个
server_namedomain1.comwww.domain1.com;
#访问日志,和上面的级别不一样,应该是下级的覆盖上级的
access_loglogs/domain1.access.logmain;
roothtml;
location/{
indexindex.htmlindex.htmindex.php;
}
#所有php后缀的,都通过fastcgi发送到1025端口上
#上面include的fastcgi.conf在此应该是有作用,如果你不include,那么就把fastcgi.conf的配置项放在这个下面。
location~.php${
fastcgi_pass127.0.0.1:1025;
}
}
#这个是反向代理的例子
server{#simplereverse-proxy
listen80;
server_namedomain2.comwww.domain2.com;
access_loglogs/domain2.access.logmain;
#静态文件,nginx自己处理
location~^/(images|javascript|js|css|flash|media|static)/{
root/var/www/virtual/big.server.com/htdocs;
#过期30天,静态文件不怎么更新,过期可以设大一点,如果频繁更新,则可以设置得小一点。
expires30d;
}
#把请求转发给后台web服务器,反向代理和fastcgi的区别是,反向代理后面是web服务器,fastcgi后台是fasstcgi监听进程,当然,协议也不一样。
location/{
proxy_pass
}
#upstream的负载均衡,weight是权重,可以根据机器配置定义权重。据说nginx可以根据后台响应时间调整。后台需要多个web服务器。
01 | upstreambig_server_com{ |
02 | server127.0.0.3:8000weight=5; |
03 | server127.0.0.3:8001weight=5; |
04 | server192.168.0.1:8000; |
05 | server192.168.0.1:8001; |
06 | } |
07 |
08 | server{ |
09 | listen80; |
10 | server_namebig.server.com; |
11 | access_loglogs/big.server.access.logmain; |
12 |
13 | location/{ |
14 | proxy_passhttp: //big_server_com; |
15 | } |
16 | } |
17 | } |
Nginx安置后只有一个法式文件,自己并不供给各类办理法式,它是利用参数和体系旌旗灯号机制对Nginx历程自己举行节制的。Nginx的参数包罗有如下几个:
-c:利用指定的设置装备摆设文件而不是conf目次下的nginx.conf。
-t:测试设置装备摆设文件是否准确,在运行时必要从头加载设置装备摆设的时辰,此号令很是主要,用来检测所点窜的设置装备摆设文件是否有语法错误。
-v:表现nginx版本号。
-V:表现nginx的版本号以及编译情况信息以及编译时的参数。
比方我们要测试某个设置装备摆设文件是否誊写准确,我们可以利用以下号令
sbin/nginx–t–cconf/nginx2.conf
相关文章推荐
- 使用ab对nginx进行压力测试
- 重启或杀掉nginx进程后丢失nginx.pid
- Windows安装Nginx并支持PHP
- Nginx的安装和配置文件详细说明
- Nginx 499错误的原因及解决方法
- Nginx+phpfastcgi下flush输出问题
- 编译nginx时,编译参数注意点
- Nginx+Keepalived实现
- nginx无法启动: libpcre.so.1/libpcre.so.0: cannot open shared object file解决办法
- nginx proxy超时报错 upstream timed out (110: Connec...
- linux/centos安装nginx常见错误及解决办法【make错误,需要yum -y install openssl openssl-devel或者自己下载然后重新./configure】
- mysql php nginx
- nginx安装-del
- nginx 配置虚拟主机
- 【Nginx探究系列二】Nginx配置篇之客户Nginx白名单访问配置
- 为你的网站开启 gzip 压缩功能(nodejs、nginx)
- nginx 反向跳转
- NGINX 安装&配置
- 解决Nginx的connect() to 127.0.0.1:8080 failed (13: Permission denied) while connect
- centos 6.5 配置nginx环境