nginx学习总结三(nginx的基本配置)
装nginx简单但是必须装pcre这个包。# tar zxvf pcre-7.9.tar.gz
# cd pcre-7.9/
# ./configure
# make && make install
# tar zxvf nginx-0.7.65.tar.gz
# cd nginx-0.7.65/
#./configure
# make && make install
useradd nginx -M -s /sbin/nologin
按照默认安装 vi /usr/local/nginx/conf/nginx.conf
usernginx nginx;
#运行的用户和组 我一般是采用www用户的。
worker_processes1;
#指定工作的进程数 一般是CPU总核数的2倍或相等(我这里是虚拟机所以就一个)
例如是2个2核的写4就可以了
#error_loglogs/error.log; #错误日志的路径
#error_loglogs/error.lognotice;
#日志的级别{debug |info |notice |warn |errro |crit}
#error_loglogs/error.loginfo;
#pid logs/nginx.pid; #pid 进程的日志
worker_rlimit_nofile 51200; #打开文件的数量
events {
use epoll; #使用的模型前面讲到了
worker_connections51200;#允许连接数
}
http {
include mime.types;
default_typeapplication/octet-stream;
#charset gb2312;
# 设置使用的字符集 ,多个网站的请勿乱设置。
#log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#使用日志记录相当于apache的combined日志格式。。。
#access_loglogs/access.logmain;
sendfile on;
#tcp_nopush on;
#keepalive_timeout0;
keepalive_timeout65;
#gzipon;
#gzip#头部压缩缓存是否开启。
include vhosts/*.conf;
#区配这个目录下的配置文件我习惯一个虚拟主机一个配置文件
}
#mkdir/usr/local/nginx/conf/vhosts/
# vi /usr/local/nginx/conf/vhosts/hou.conf
server {
listen 80;
#监听端口
server_nametest1.xywy.com;
#域名
#charset koi8-r;
#这个虚拟主机用的字符集
#access_loglogs/host.access.logmain;
#针对每个域名记录日志
location / {
root /www;
# 虚拟主机目录
indexindex.html index.htm index.php; #访问页
}
#error_page404 /404.html; #400错误吧
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504/50x.html;
location = /50x.html {
root html;
}
}
保存启动服务,最基本的nginx的搭建就出来了 呵呵高兴吧。
页:
[1]