安装nginx:
wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
2 安装这个rpm包
rpm -ivhnginx-release-centos-6-0.el6.ngx.noarch.rpm
安装过程中会出现错误提示:
warning:nginx-release-centos-6-0.el6.ngx.noarch.rpm: Header V4 RSA/SHA1 Signature, keyID 7bd9bf62: NOKEY
忽略即可
3 开始正式安装nginx
yum install nginx
会显示一大堆信息:Is this ok [y/N]:
输入y,屏幕滚了一会之后就安装完毕,最后提示“Complete!”就是安完了。
4 nginx的几个默认目录
输入命令: whereis nginx
nginx: /usr/sbin/nginx /etc/nginx/usr/share/nginx
1) 配置所在目录:/etc/nginx/
2) PID目录:/var/run/nginx.pid
3) 错误日志:/var/log/nginx/error.log
4) 访问日志:/var/log/nginx/access.log
5) 默认站点目录:/usr/share/nginx/html
[root@www vfast]# vi /etc/nginx/nginx.conf
user nginx; ---用户
worker_processes 1; --可设置成cpu核数
error_log /var/log/nginx/error.log warn; --错误日志
pid /var/run/nginx.pid;
events {
worker_connections 1024;--设置连接数最大值
}
http {
include /etc/nginx/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"';
日志类型:$remote_addr 客户端IP地址
$remote_user 客户端用户名称
$time_local 访问时间和时区
$request 请求的URL和http协议
$status 记录请求状态,成功为200
$body_bytes_sent 给客户端文件主体大小
$http_referer 从哪个页面链接过来的
$http_user_agent 用户浏览器
$http_x_forwarded_for
access_log /var/log/nginx/access.log main; 访问日志路径和格式
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;保持活动超时时间,超过之后服务器会关闭连接
#gzip on;
include /etc/nginx/conf.d/*.conf;
server{
listen 80; --监听端口
server_name www.charles.com; --域名或者是IP地址
location / { location可以理解为匹配 /代表匹配所有
root /tmp/www; 网站根路径该root不是用户是根的意思后接网站路径
index index.html index.htm;
}
location ~*\.php$ { location可以理解为匹配 ~*代表不区分大小写
proxy_pass http://192.168.1.106; 以.Php结尾的转发给后面的IP
}
error_page 404 /404.html; 定义错误日志
location =/404.html{
root /tmp/www;
}
}
server{
listen 80;
server_name www.vfast.com;
location / {
root /tmp/vfast;
index index.html index.htm;
}
error_page 404 /404.html;
location =/404.html{
root /tmp/vfast;
}
}
# error_page 404 /404.html;
# location =/404.html{
# root /tmp/vfast
# }
}