Nginx安装:
Step1、在modules目录下创建nginx目录
[root@master /]# mkdir /opt/modules/nginx
Step2、下载安装包
[root@master /]# wget http://tengine.taobao.org/download/tengine-2.0.2.tar.gz
Step3、解压到指定目录:
[root@master /]# tar -zxf tengine-2.0.2.tar.gz /opt/modules/nginx
step4、安装依赖服务
[root@master /]# yum -y install gcc openssl-devel zlib-devel pcre-devel
Step5、部署安装
[root@master /]# ./configure
[root@master /]# make && make install
[root@master tengine-2.0.2]# cd /usr/local/nginx/
目录结构
* 安装目录:/usr/local/nginx/
* 操作命令目录:/usr/local/nginx/sbin
* 配置文件目录:/usr/local/nginx/conf
* 默认的页面存储目录:/usr/local/nginx/html
操作命令
* 启动Nginx
# sbin/nginx
* 查看Nginx进程是否存在
# ps -ef | grep nginx
* 关闭服务
# sbin/nginx -s stop
* 重新加载配置项
# sbin/nginx -s reload
* 校验conf文件夹中nginx.conf文件格式是否正确
# sbin/nginx -t
* 帮助命令
# sbin/nginx -h
访问web页面:
localhost/
如果访问不成功,检查防火墙:
[root@master nginx]# systemctl status firewalld
nginx配置:
参考文档:
http://tengine.taobao.org/document/http_upstream_dynamic.html
step1 数据备份:
[root@master conf]# cp nginx.conf nginx.conf.bak
step2更改配置:
[root@master conf]# vi nginx.conf
# http标签中添加如下
# 定义日志格式
log_format user_log_format '$remote_addr^A$msec^A$request_uri';
# server标签中添加如下
server_name hadoop-master01 hadoop-master01.sjzc.com;
# server标签中添加location标签如下
# 新增一个location,匹配所有以what.png结尾的请求
location ~ .*(what)\.(png)$ {
# 设置请求类型为图片请求
default_type image/png;
# 记录日志,存储到一个flume用户可以读取的文件夹中,需要修改权限
access_log /usr/local/nginx/user_logs/access.log user_log_format;
# 给定存储图片的服务器位置
root /usr/local/nginx/html;
}
step3修改nginx.conf用户以及用户组 root:root
[root@master conf]# chown root:root nginx.conf
[root@master conf]# ls -al nginx.conf
-rw-r--r--. 1 root root 3268 4月 18 15:46 nginx.conf
step4修改nginx.conf的权限为644
[root@master conf]# chmod 644 nginx.conf
[root@master conf]# ls -al nginx.conf
-rw-r--r--. 1 root root 3268 4月 18 15:46 nginx.conf
step5创建存储用户日志文件夹/usr/local/nginx/user_logs,并将其权限修改为777
[root@master conf]# mkdir /usr/local/nginx/user_logs
[root@master nginx]# chmod 777 user_logs/
Step6、将本机上传的what.png图片文件移动到/usr/local/nginx/html文件夹中,并修改用户及权限和该文件夹中的其他文件一样
[root@master nginx]# cp /opt/softwares/what.png /usr/local/nginx/html/
Step7、重启Nginx服务
方式一:
# cat /usr/local/nginx/logs/nginx.pid
# kill -9 xxxxx
方式二:
# ps -ef | grep nginx
# kill -9 xxxxx
方式三:
# sbin/nginx -s stop
重启:
# sbin/nginx
Step8、进行网页刷新测试,观察access_log下是否产生日志
811

被折叠的 条评论
为什么被折叠?



