詳解nginx安裝過程并代理下載服務器文件
主旨
nginx服務,現(xiàn)在是最好用的一種代理服務,日常我們代理的一般都是端口轉發(fā)和流量控制,那么我們如何通過nginx來實現(xiàn)文件下載呢?就是通過nginx服務,通過url來下載文件。
Nginx是一款輕量級的web服務器/反向代理服務器及電子郵件(IMAP/POP3)代理服務器,在BSD-like 協(xié)議下發(fā)行。其特點是占有內存少,并發(fā)能力強,事實上nginx的并發(fā)能力在同類型的網頁服務器中表現(xiàn)較好。
環(huán)境
linux服務器
nginx軟件
軟件下載
鏈接: https://pan.baidu.com/s/1GvEwxsk26NJRuy2gyOSvjw?pwd=sa59
提取碼: sa59
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]$ cd pcre-8.35/ [yunweijia@localhost pcre-8.35]$ sudo ./configure # 編譯 [yunweijia@localhost pcre-8.35]$ sudo make && make instal # 安裝 [yunweijia@localhost pcre-8.35]$ 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]$ 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]$ 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]$ sudo ./sbin/nginx # 啟動
6、驗證
在"/home/yunweijia/txt/"中新建文件,測試下載。
下載url為:http://ip地址:端口號/文件名
[yunweijia@localhost nginx]$ mkdir /home/yunweijia/txt/ [yunweijia@localhost nginx]$ 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代理文件下載完畢。
到此這篇關于詳解nginx安裝過程并代理下載服務器文件的文章就介紹到這了,更多相關nginx代理下載服務器文件內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Nginx 緩存系統(tǒng) proxy_cache工作原理解析
Nginx 的 proxy_cache 模塊允許 Nginx 作為反向代理服務器時緩存后端服務器的響應,本文給大家介紹Nginx 緩存系統(tǒng) proxy_cache的工作原理,感興趣的朋友跟隨小編一起看看吧2024-12-12Ubuntu上安裝Nginx服務器程序及簡單的環(huán)境配置小結
Nginx是一款高性能的異步非阻塞服務器應用程序,人氣相當高,這里我們就來看一下在Ubuntu上安裝Nginx服務器程序及簡單的環(huán)境配置小結:2016-07-07