linux安装nginx搭建服务并实现文件服务器和代理服务器配置

1.课题的背景和意义

  由于编码过程中需要进行文件上传服务,文件上传后 需要有http资源的路径需要访问。原则上可以通过Apache 、iis 、nginx 等方式映射文件夹为网站即可实现。由于使用linux环境,nginx安装方便快捷,故采用nginx来实现;

  域名资源宝贵,申请额外的域名流程繁琐;

  需要多个文件服务器,使用同一个域名代理进行访问。

2.环境资料准备

linux服务器一台 centos

nginx 依赖包 gcc zlib zlib-devel pcre-devel openssl openssl-devel 等;

nginx 安装包 http://nginx.org/en/download.html

3.安装、设计与实现

设计思路:

第一步 安装依赖包:yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

第二步 解压、编译nginx源码并安装

  tar -xvf nginx-1.19.8.tar.gz

  cd nginx-1.19.8/

  ./configure (若依赖包未安装 此处会报错,安装响应的依赖包即可 yum -y install gcc-c++)

  make

  make install 默认安装目录为:/usr/local/nginx/     配置文件位置:/usr/local/nginx/conf/nginx.conf

   vi /usr/local/nginx/conf/nginx.conf 修改配置文件

  cd /usr/local/nginx

  ./nginx  运行  若修改配置文件后 需要reload nginx 命令为:./nginx -s reload

第三步:使用nginx 搭建三台服务器、 并搭建代理服务器,使用二级目录代理前面提到的三台服务器;

    1.建立文件目录三个;

      /mydata/weixin_sc/images

      /mydata/weixin_sc/uploadfiles

      /mydata/weixin_sc/wxweb

    2 nginx.conf修改配置 :


  #user  nobody;
  worker_processes 1;   #error_log logs/error.log;
  #error_log logs/error.log notice;
  #error_log logs/error.log info;   #pid logs/nginx.pid;   events {
worker_connections 1024;
  }   http {
include 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"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; #文件服务器1
server {
listen 8991;
server_name localhost;
location / {
root /mydata/weixin_sc/images;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} }
#文件服务器2
server {
listen 8992;
server_name localhost;
location / {
root /mydata/weixin_sc/uploadfiles;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#文件服务器3
server {
listen 8993;
server_name localhost;
location / {
root /mydata/weixin_sc/wxweb;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#代理服务器
server {
listen 8994;
#listen 443 ssl;
server_name localhost;
#client_max_body_size 10M;
#启用 SSL 功能, deprecated
#ssl on;
#证书文件名称
#ssl_certificate
#私钥文件名称
#ssl_certificate_key
#ssl_session_timeout 5m;
#请按照以下协议配置
#ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
#ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
#ssl_prefer_server_ciphers on; add_header X-Frame-Options SAMEORIGIN; #不允许iframe嵌套 location / {
proxy_pass http://localhost:8991;
} #使用二级目录代理三台文件服务器,节约域名。; 注意 代理路径 /,有无/会影响代理服务,是否传递目录问题; location /images/ {
proxy_pass http://localhost:8991/;
}
location /uploadfiles/ {
proxy_pass http://localhost:8992/;
}
location /wxweb/ {
proxy_pass http://localhost:8993/;
} } }

重启ng服务: ./nginx -s reload

扩展学习:

查看nginx进程是否启动:

ps -ef | grep nginx

启动,关闭,重启,命令:

./nginx 启动

./nginx -s stop 关闭

./nginx -s reload 重启

参考文献:

http://nginx.org/

http://nginx.org/en/docs/

    

linux安装nginx 并配置文件服务器和代理服务器的更多相关文章

  1. linux安装Nginx 以及 keepalived 管理Nginx

    linux安装Nginx 1.1将Nginx素材内容上传到/usr/local目录(pcre,zlib,openssl,nginx)(注意:必须登录用对这个文件具有操作权限的) 1.2安装pcre库 ...

  2. linux学习(十一)linux安装nginx

    一.前言 由于本地练手的小demo用的是vue+spring boot来玩的,所以部署的时候想着用Nginx来实现反向代理[即请求转发,解决前后端分离的跨域请求问题],既然要用,那么首先得在服务器上面 ...

  3. Linux安装nginx代理服务器

    Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器. ...

  4. 【转】 linux 安装nginx及编译参数详解

    版权声明:本文为博主原创文章,未经博主允许不得转载. 从官网下载一个nginx 的tar.gz 版. 安装方式使用make 安装 第一步:解压 tar -zxvf  nginx-1.7.4.tar.g ...

  5. Linux 安装Nginx(使用Mac远程访问)

    阅读本文需要一定的Linux基础 一 Nginx简介 nginx是用c语言编写的一款高性能的http服务器|反向代理服务器|电子邮件(IMAP/POP3)代理服务器 由俄罗斯的程序设计师Igor Sy ...

  6. linux 安装 nginx 及反向代理配置

    Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器,以下为Linux centos平台下安装nginx并配置反向代理的过程(采用源码安装的方式) 一:安装 ...

  7. Linux安装Nginx以及简单理解

    1.Nginx简单介绍 ①.Nginx:一个高性能的HTTP和反向代理服务器,高并发处理很不错. ②.反向代理:在计算机世界里,由于单个服务器的处理客户端(用户)请求能力有一个极限,当用户的接入请求蜂 ...

  8. linux安装nginx,遇坑解决

    1.nginx官网下载tar包,解压linux下: 2.进入解压文件夹,执行./configure: 3.报错,原因没有安装nginx相关依赖,如gcc环境,PCRE依赖库 ,zlib 依赖库 ,Op ...

  9. Linux 安装Nginx+PHP+MySQL教程

    一.安装nginx 通过yum安装openssl: yum -y install openssl openssl-devel 通过yum安装pcre: yum -y install pcre-deve ...

随机推荐

  1. docker-compose All In One

    docker-compose All In One docker-compose 多容器应用 $ docker-compose -h Define and run multi-container ap ...

  2. we have a problem with promise

    we have a problem with promise Q: What is the difference between these four promises? doSomething() ...

  3. WEB 面向开发者的结构化数据

    通常用于google搜索 See also: video 探索搜索库

  4. 闲着蛋疼看下a++的过程

    赋值过程 int a = 1; int b = a++; x86 反汇编: int a = 1; 00D06428 C7 45 F8 01 00 00 00 mov dword ptr [a],1 i ...

  5. NGK算力市场,不止有动静态收益还有SPC空投!

    随着数字货币交易的火热,云算力挖矿也悄然崛起.越来越多的用户开启云算力挖矿,以获取更多的收益.相较于传统的矿机挖矿,用户通过购买算力进行云挖矿,节省了购买矿机以及维护的成本.另一方面,也降低了安全风险 ...

  6. 2020 NGK 全球启动大会于美国硅谷圆满落幕

    据NCC报道美国西海岸时间11月25日,NGK全球启动大会在美国加利福尼亚北部的硅谷会展中心成功举办.本次大会吸引了来自世界各地的企业家.创业者.开发者,以及投资人达一万人次齐聚硅谷. NGK创始人. ...

  7. spring扩展点整理

    本文转载自spring扩展点整理 背景 Spring的强大和灵活性不用再强调了.而灵活性就是通过一系列的扩展点来实现的,这些扩展点给应用程序提供了参与Spring容器创建的过程,好多定制化的东西都需要 ...

  8. Flex实现左右布局

    html <div class="business-content-1"> <div class="item"> 111 </di ...

  9. 基于ros2 dashing的建图导航探索

    基于ros2 dashing的建图导航探索 1. 环境准备 安装ros2 dashing, 参考链接: https://index.ros.org/doc/ros2/Installation/Dash ...

  10. Portainer中文汉化

    一.概述 Portainer是Docker的图形化管理工具,提供状态显示面板.应用模板快速部署.容器镜像网络数据卷的基本操作(包括上传下载镜像,创建容器等操作).事件日志显示.容器控制台操作.Swar ...