准备
将nginx放到yum repro库中
[root@localhost ~]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm 获取http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm 警告:/var/tmp/rpm-tmp.aGUxnB: 头V4 RSA/SHA1 Signature, 密钥 ID 7bd9bf62: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:nginx-release-centos-7-0.el7.ngx ################################# [100%] [root@localhost ~]#
查看nginx信息
[root@localhost ~]# yum info nginx 已加载插件:fastestmirror nginx | 2.9 kB 00:00:00 nginx/x86_64/primary_db | 24 kB 00:00:00 Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.btte.net * updates: mirrors.aliyun.com 可安装的软件包 名称 :nginx 架构 :x86_64 时期 :1 版本 :1.12.0 发布 :1.el7.ngx 大小 :716 k 源 :nginx/x86_64 简介 : High performance web server 网址 :http://nginx.org/ 协议 : 2-clause BSD-like license 描述 : nginx [engine x] is an HTTP and reverse proxy server, as well as : a mail proxy server.
安装
[root@localhost ~]# yum install nginx -y
启动
[root@localhost ~]# service nginx start Redirecting to /bin/systemctl start nginx.service [root@localhost ~]# nginx -v nginx version: nginx/1.12.0 [root@localhost ~]# ss -tnlp State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:80 *:* users:(("nginx",pid=9753,fd=6),("nginx",pid=9752,fd=6)) LISTEN 0 128 *:22 *:* users:(("sshd",pid=1179,fd=3)) LISTEN 0 100 127.0.0.1:25 *:* users:(("master",pid=1758,fd=13)) LISTEN 0 128 :::22 :::* users:(("sshd",pid=1179,fd=4)) LISTEN 0 100 ::1:25 :::* users:(("master",pid=1758,fd=14)) [root@localhost ~]#
配置
[root@localhost ~]# find / -name nginx.conf /etc/nginx/nginx.conf [root@localhost ~]# cd /etc/nginx/ [root@localhost nginx]# cd conf.d/ [root@localhost conf.d]# vi toms-file.conf server { listen 80; server_name 192.168.1.9; index index.html index.htm index.php; root /pdf_data/pdf; charset utf-8; location / { autoindex on; autoindex_exact_size on; autoindex_localtime on; if ($request_filename ~* ^.*?\.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$){ add_header Content-Disposition: 'attachment;'; } } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|mp3)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 30d; } }
立即生效
[root@localhost conf.d]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@localhost conf.d]# service nginx restart Redirecting to /bin/systemctl restart nginx.service
结合上面创建目录存放目录
[root@localhost conf.d]# mkdir -p /pdf_data/pdf
继续阅读
- 我的QQ
- QQ扫一扫
-
- 我的头条
- 头条扫一扫
-
评论