当前位置:首页 > 技术文章 > 正文内容

如何安装nginx并代理下载服务器文件

arlanguage4个月前 (12-29)技术文章46

声明:本文乃“运维家”原创,转载请注明出处,更多内容请关注公众号“运维家”。



主旨

nginx服务,现在是最好用的一种代理服务,日常我们代理的一般都是端口转发和流量控制,那么我们如何通过nginx来实现文件下载呢?就是通过nginx服务,通过url来下载文件。


Nginx是一款轻量级的web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,在BSD-like 协议下发行。其特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型的网页服务器中表现较好。


环境

linux服务器
nginx软件


软件下载

公众号“运维家”后台回复“nginx”,即可获取下载地址。


nginx安装


1、安装编译工具及库文件

[yunweijia@localhost jier]$ sudo yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

?


2、安装 PCRE

[yunweijia@localhost jier]$ cd /usr/local/src/
[yunweijia@localhost src]$ sudo wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz  下载
[yunweijia@localhost src]$ sudo tar xf pcre-8.35.tar.gz  # 解压
[yunweijia@localhost src]nbsp;cd pcre-8.35/
[yunweijia@localhost pcre-8.35]nbsp;sudo ./configure  # 编译
[yunweijia@localhost pcre-8.35]$ sudo make && make instal  # 安装
[yunweijia@localhost pcre-8.35]nbsp;pcre-config --version  # 版本查看
8.32
[yunweijia@localhost pcre-8.35]$ 


3、安装nginx

[yunweijia@localhost jier]$ pwd
/home/yunweijia/jier
[yunweijia@localhost jier]$ ls
nginx-1.14.2.tar.gz
[yunweijia@localhost jier]$ tar xf nginx-1.14.2.tar.gz 
[yunweijia@localhost jier]nbsp;cd nginx-1.14.2/
[yunweijia@localhost nginx-1.14.2]$ sudo ./configure --prefix=/home/yunweijia/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
[yunweijia@localhost nginx-1.14.2]$ sudo make && make install

4、配置调整

[yunweijia@localhost nginx-1.14.2]$ cd /home/yunweijia/nginx/
[yunweijia@localhost nginx]$ ls
conf  html  logs  sbin
[yunweijia@localhost nginx]$ vim conf/nginx.conf
# 以下内容是配置文件的第二行进行配置
user root;
# 以下配置是唉server中进行新增
        location ~* (.*.txt) {  # 代理后缀为txt的
            add_header  Content-Type    "application/octet-stream";
            if ( $args ~ ^filename=(.*) ) {
                add_header  Content-Disposition "attachment; filename=$1";
            }
            yunweijia /home/yunweijia/txt/;  # 在这个目录下
        }

5、启动nginx

[yunweijia@localhost nginx]nbsp;sudo ./sbin/nginx -t  # 检查配置
nginx: the configuration file /home/yunweijia/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /home/yunweijia/nginx/conf/nginx.conf test is successful
[yunweijia@localhost nginx]nbsp;sudo ./sbin/nginx  # 启动

6、验证

在"/home/yunweijia/txt/"中新建文件,测试下载。

下载url为:http://ip地址:端口号/文件名


[yunweijia@localhost nginx]$ mkdir /home/yunweijia/txt/
[yunweijia@localhost nginx]nbsp;cd /home/yunweijia/txt/
[yunweijia@localhost txt]$ ls
[yunweijia@localhost txt]$ echo ceshi > 1.txt
[yunweijia@localhost txt]$ cat 1.txt 
ceshi
[yunweijia@localhost txt]$

浏览器输入地址为:http://192.168.112.130/1.txt

文件下载成功。

至此,用nginx代理文件下载完毕。

扫描二维码推送至手机访问。

版权声明:本文由AR编程网发布,如需转载请注明出处。

本文链接:http://www.arlanguage.com/post/529.html

标签: nginx 后缀名
分享给朋友:

“如何安装nginx并代理下载服务器文件” 的相关文章

一文说清nginx规则匹配(含案例分析)

概述: 在nginx中,匹配分很多情形,例如:区分大小写匹配、不区分大小写匹配、有强匹配开头、有模糊匹配某些字符、有匹配后重写动作、有匹配反向代理动作、有匹配后终止操作、还有匹配全局变量类型等等,在很多情形中,匹配动作也存在优先策略,来看看下面的案例。案例一、 server { .............

给你的Nginx加个防火墙

引言朋友的一个 WordPress 站经常访问慢。看了一下日志,发现整天被扫描网站目录,如phpmyadmin 或者 SQL 文件,和被 CC攻击。找了一下,发现 ngx_lua_waf 是个不错的方案,但是太久不更新了,而且代码我看不懂,猝最后找到 oneinstack 一键包内置的 ngx_lu...

听说你的Nginx还不会记录Response Body?

相信大家都遇到过在排查线上问题或Debug的时候,在某一瞬间,特别想开启Nginx的Response Body日志,来帮助自己快速的定位问题;但找半天发现只有$request_body/$upstream_addr/$upstream_response_time这些相近变量可用;这个时候不要慌......

5分钟搞懂nginx的location匹配规则

目录概述location介绍location指令语法location配置实例解析location常用场景实战禁止访问.sh后缀的文件实例php7进阶到架构师相关阅读概述这是关于php进阶到架构之Nginx进阶学习的第一篇文章:5分钟搞懂nginx的location匹配规则第一篇:5分钟搞懂nginx...

服务器排障nginx 499 错误地解决

问题描述:近期平台对外开放了数据查询接口,在数据量特别大时,返回结果时间可能会超过3秒,接口开放后,系统本身调用没有问题,其他第三方平台接入时,总会报链接超时问题;问题原因:查看tomcat日志无任何错误,一开始以为是tomcat接收参数最大限制问题,对tomcat做了一次整体优化,修改连接数、修改...

nginx配置静态资源服务器 nginx配置静态资源服务器的方法

nginx服务器搭建在这就不过多的说明了,本内容主要是nginx静态资源服务器配置相关说明nginx配置location / :指所有的url请求都会去访问static下面的文件;指定url后缀要与文件目录后面的后缀一一对应有两种用法:root:绝对路径;alias: nginx安装目录中的stat...