[[email protected] ~]# grep -v '^#' /usr/local/nginx/conf/nginx.conf |grep -v '#' |uniq
user www; //以www用户身份启动nginx
worker_processes 1; //nginx启动的时候产生多少个后台worker process进程,通常设置成和cpu的数量相等
events {
use epoll; //epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能
worker_connections 1024; //单个后台worker process进程的最大并发链接数
}
http {
include mime.types; //设定mime类型,类型由mime.type文件定义
default_type application/octet-stream;
sendfile on; //sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,对于普通应用,必须设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,以平衡磁盘与网络I/O处理速度,降低系统的uptime.
keepalive_timeout 65; //连接超时时间
gzip on; //开启gzip压缩
server {
listen 80; //侦听80端口
server_name 192.168.122.50; //定义使用192.168.122.50这个ip访问
location / {
root html; //定义服务器的默认网站根目录位置
index index.php index.html index.htm; //定义首页索引文件的名称
}
error_page 500 502 503 504 /50x.html; //定义错误提示页面
location = /50x.html {
root html;
}
location ~ .php$ { //定义php解析
root html;
fastcgi_pass 127.0.0.1:9000; //定义解析php程序使用的FastCGI接口
fastcgi_index index.php; //定义PHP程序首页索引文件的名称
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
}
server { //定义第一台虚拟主机
listen 80;
server_name website1.yang.com;
location / {
root /www/website1;
index index.html index.htm;
}
}
server { //定义第二台虚拟主机
listen 80;
server_name website2.yang.com;
location / {
root /www/website2;
index index.html index.htm;
}
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/website2$fastcgi_script_name;
include fastcgi_params;
}
}
}
[[email protected] ~]# /usr/local/nginx/sbin/nginx -t //测试语法
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful
[[email protected] ~]# service nginx restart
声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。