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. 如何给 GitHub 添加 SSH key, 如何生成 SSH key 详细图文教程!

    如何给 GitHub 添加  SSH key, 如何生成  SSH key 详细图文教程! 一. 生成  SSH key https://ide.c9.io/xgqfrms/ 创建一个空项目:(或使用 ...

  2. webpack 5

    webpack 5 webpack 5 requires at least Node.js 10.13.0 (LTS). https://webpack.js.org/migrate/5/ https ...

  3. Android Studio show whitespace & Android studio 设置注释缩进

    Android Studio show whitespace & Android studio 设置注释缩进 https://github.com/xgqfrms/flutter/issues ...

  4. Suspense for Data Fetching

    Suspense for Data Fetching Experimental https://reactjs.org/docs/concurrent-mode-suspense.html React ...

  5. 「NGK每日快讯」2021.1.4日NGK第62期官方快讯!

  6. C++ 多线程使用future传递异常

    如果 std::async 调用的函数抛出异常,那么这个异常会被存储在值的位置,同时 future 变为 ready ,如果调用 get() 会重新抛出存储的异常. Note: 标准并没有指定原来的异 ...

  7. 最实用JS 留着学习

    1.A标签删除 function input(){    var b = window.confirm("确认要删除本条信息!");    if(b==true){     ret ...

  8. WPF 之绘画(十一)

    一.WPF 绘画 WPF 可以绘制线段(Line).矩形(Rectange).椭圆(Ellipse).路径(Path).具体使用如下所示: <!--(1)线段:Line--> <Li ...

  9. Python网络编程相关的库与爬虫基础

    PythonWeb编程 ①相关的库:urlib.urlib2.requests python中自带urlib和urlib2,他们主要使用函数如下: urllib: urlib.urlopen() ur ...

  10. 链表算法题二,还原题目,用debug调试搞懂每一道题

    文章简述 大家好,本篇是个人的第4篇文章. 承接第3篇文章<开启算法之路,还原题目,用debug调试搞懂每一道题>,本篇文章继续分享关于链表的算法题目. 本篇文章共有5道题目 一,反转链表 ...