在centos上搭建nginx图片服务器(包含上传模块)

合集下载

nginx搭建图片服务器的过程详解(root和alias的区别)

nginx搭建图片服务器的过程详解(root和alias的区别)

nginx搭建图⽚服务器的过程详解(root和alias的区别)安装过程略(我是直接⽤yum -y install nginx;安装的)。

启动启动(重启)nginx,以下2个命令都可以:systemctl restart nginx;# 注:这⾥的nginx不是⽬录,是cd不进去的/usr/sbin/nginx -s reload;⼀般不报错就是启动成功。

页⾯验证nginx是否启动浏览器输⼊ip,返回centos页⾯,这不对吧?看下配置⽂件:root /usr/share/nginx/html;该⽬录下的index.html 内容就是centos⾸页内容,说明没问题,nignx启动了(也可以改下index.html的title确定下)。

准备⼯作mkdir -p /data/images; # 创建图⽚⽂件存放⽬录chmod -R 755 /data/images; # 授权cd /data/images;然后 rz 命令上传个图⽚01.pngvim /etc/nginx.conf,添加配置:location /images {root /data;autoindex on;}浏览器输⼊:111.222.333.444/data/images/01.png;出现图⽚,表⽰成功了。

使⽤alias配置使⽤alias当然也是可以的:location /images {alias /data/images; # 说是后⾯必须要加'/',这⾥实测不加也可以autoindex on;}如下写法有问题:location /images {alias /data;autoindex on;}问题在哪?地址栏输⼊ /images/01.png 是获取不到的。

因为 /images 会映射到 /data ,但是实际⽬录是 /data/images/01.png,所以少了个images。

错误配置实际可能不会那么顺利,会踩很多坑。

CentOS8下Nginx使用教程

CentOS8下Nginx使用教程

CentOS8下Nginx使⽤教程1、nginx安装dnf install nginx -y2、nginx常⽤⽬录nginx.conf⽬录:/etc/nginx.nginx.confnginx启动⽬录:/usr/sbin/nginx3、nginx热部署所谓热部署,就是配置⽂件nginx.conf修改后,不需要stop Nginx,不需要中断请求,就能让配置⽂件⽣效!/usr/sbin/nginx -s reload4、配置nginx 访问资源⽬录修改 nginx.conf 配置⽂件,在service标签内部加⼊下⾯的location,通过访问 ip地址:端⼝/source 就能访问 /home/source ⽬录了。

location /source { root /home; autoindex:on;}还可以有如下写法:location /source { alias /home/source; autoindex:on;}5、反向代理听着反向代理是不是很⽜逼的事,实际上很容易理解:正向代理:A要访问C的地址,但是由于⽹络或是墙的问题,A不能直接访问到C,但是呢有个B可以访问C,A也可以访问B,那么A在访问C的时候通过B代理,这就是正向代理。

A ---/---> C ; A ------>B ; B ------>C ;那么 A ------> B ------> C反向代理:A要访问C的地址,但是由于⽹络或安全的问题,A不能直接访问到C,但是呢有个B可以访问C,A也可以访问B,那么A在访问C的时候通过B代理,这就是正向代理。

A ---/---> C ; A ------>B ; B ------>C ;那么 A ------> B ------> C通过上⾯的⽰例是不是觉得 正向代理和反向代理⼀样?对,确实原理⼀样,但是有有个明显的差别就是:在正向代理中 A访问C,A是明确知道C的地址(要想访问)。

centos6.5服务器安装Nginx设置服务和开机自启的方法

centos6.5服务器安装Nginx设置服务和开机自启的方法

centos6.5服务器安装Nginx设置服务和开机⾃启的⽅法本⽂介绍了centos6.5服务器安装Nginx设置服务和开机⾃启的⽅法,分享给⼤家,也给⾃⼰留个笔记1、安装Nginx及其依赖⾸先是⽼套路,使⽤ssh链接服务器,还记得以前的代码吗?ssh -t ⽤户名@服务器IP或者域名 -p 22<!--⽤户名⼀般是root,⽅便操作,我的登录代码如下-->ssh -t root@ -p 22在终端中输⼊上⾯命令按下回车,要求我们输⼊密码,这个密码是不可见的,所以⼀定要输⼊正确。

链接到服务器后,我们切换到常⽤的安装路径,当然我服务器上⾯的安装路径是/usr/src,接着开始在终端操作:<!--切换到安装⽬录下-->cd /usr/src<!--创建Nginx⽂件夹⽤来存放Nginx相关的资源和依赖-->mkdir Nginx<!--下载资源和依赖-->yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel<!--上⾯的命令⼀般来说会是不需要安装什么,不过这都不重要,我们接着会重新安装指定的版本--><!--下载pcre-->wget ftp:///pub/software/programming/pcre/pcre-8.40.tar.gz<!--解压-->tar -zxvf pcre-8.40.tar.gz<!--切换到pcre⽬录-->cd pcre-8.40<!--设置-->./configure<!--编译-->make<!--安装-->make install<!--切换到Nginx主⽬录-->cd ..<!--下载及安装zlib-->wget /zlib-1.2.11.tar.gz<!--解压-->tar -zxvf zlib-1.2.11.tar.gz<!--切换到zlib⽬录-->cd zlib-1.2.11<!--设置、编译、安装-->./configuremakemake install<!--切换到Nginx主⽬录-->cd ..<!--下载及准备ssl-->wget /source/openssl-fips-2.0.14.tar.gz<!--解压-->tar -zxvf openssl-fips-2.0.14.tar.gz<!--yum安装ssl-->yum -y install openssl openssl-devel<!--下载及安装nginx-->wget /download/nginx-1.4.2.tar.gztar -zxvf nginx-1.4.2.tar.gzcd nginx-1.4.2<!--设置Nginx安装⽬录/opt/nginx,且添加ssl⽀持-->./configure --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcremakemake install到这⾥来讲,我们的nginx安装完成了,但是我们还需要做更多的事情,那就是配置服务器,添加ssl访问,设置服务和开机启动2、配置服务器互联⽹上关于服务器设置的很多,但是准确阐述的却不是那么多,⽽我刚好是在看了他们的东西后就呵呵了。

centos8.5安装nginx+开机自动启动

centos8.5安装nginx+开机自动启动

centos8.5安装nginx+开机⾃动启动下载nginx,下载地址:当前最新稳定版 nginx-1.20.2.tar.gz下载完成后通过 xftp⼯具将nginx-1.20.2.tar.gz上传到centos服务器的某个⽬录下⾯。

【nginx常⽤命令】cd /usr/local/nginx/sbin/ #进到nginx⽬录./nginx./nginx -s stop #强制停⽌./nginx -s quit #平滑停⽌./nginx -s reload #重载配置⽂年nginx -t #检查配置⽂件是否正确nginx -t -c /特定⽬录/nginx.conf #检查特定⽬录的配置⽂件是否正确ginx -v #查看版本信息【查看nginx进程信息】ps aux | grep nginxpa -ef | grep nginx安装依赖nginx依赖包:gcc、libtoolpcre、pcre-develzlib、zlib-developenssl、openssl-devel安装nginx前必须先安装这些依赖。

【安装gcc】gcc是linux下的编译器,它可以编译 C、C++、Ada、Object C、Java等语⾔。

yum -y install make gcc gcc-c++ libtool查看 gcc版本: gcc -v 或 gcc --version【安装pcre】pcre是⼀个perl库,包括perl兼容的正则表达式库,nginx的http模块使⽤pcre来解析正则表达式,所以需要安装pcre库。

yum install -y pcre pcre-devel查看pcre版本号:pcre-config --version【安装zlib】zlib库提供了很多种压缩和解压缩⽅式,nginx使⽤zlib对http包的内容进⾏gzip。

yum install -y zlib zlib-devel【安装openssl】openssl⽤来对http通讯进⾏加密。

CentOS上yum安装Nginx

CentOS上yum安装Nginx

rpm -Uvh /pub/epel/5/i386/epel-release-5-4.noarch.rpm
yum -y install nginx
设置开机启动
chkconfig nginx on
六、安装spawn-fcgi来运行php-cgi
baseurl=/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=/centos/RPM-GPG-KEY-CentOS-5
#additional packages that may be useful
CentOS上yum安装Nginx服务(PHP、Mysql、spawn-fcgi)
一、更改yum源为网易的源加快速度
vi /etc/yum.repos.d/CentOS-Base.repo
更改内容如下
# CentOS-Base.repo
#
# This file uses a new mirrorlist system developed by Lance Davis for CentOS.
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=/?release=$releasever&arch=$basearch&repo=centosplus
#baseurl=/centos/$releasever/centosplus/$basearch/
baseurl=/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=/centos/RPM-GPG-KEY-CentOS-5

基于Centos的Nginx Web服务器的构建

基于Centos的Nginx Web服务器的构建

n e w、 e a l .o m a ’ x mp e1c m; .
[ 张宴 . i 08 3 ] Ng  ̄ .. P . 1 (a C ) 建 胜 过 A ah r X+ HP5 . FS GI搭 23 t pce十
倍 的 We b服 务 器( 6版 ) t : bo. 3 . m/gn_ h v / 第 . t / lg 15 o nix p p 6 hp / s c
21 0 2年第 3 期
福 建 电

15 4
基 于 C no N ixWe 务 器 的构 建 e ts 的 gn b服
盛 铨
(浙 江 工 贸职 业技 术 学院 浙 江 温州 3 5 0 2 0 0)
【 摘 要 】 :本文简单介绍 了Ng x i 服务器概念, 了Ng x的特点和用其在 C n s n 阐述 i n et 下构建 We 服 o b
系 统 中的 C no 是 企业 Ln x发 行 版 领 头 羊 R dHa e ts iu e t
E trr eLn x的 再 编 译 版 本 ,它 完 全 免 费 , 有 的 nepi iu s 独 y m 命 令支 持 在线 升级 , 以 即时更 新 系统 。 文 主要 u 可 本 介 绍 在 C no 下 使 用 N ix构 建 We e ts gn b服 务 器 的 过 程 和方 法 。
ห้องสมุดไป่ตู้
l sre f ev/ "
lse 0 it n 8 ;
s r er e v
_
[ Ni xNgn C s y et[ SOL. t: w l_ xogNg 2 g . ix hWh Usl F / ] t / i n . / - ] n _ a h p / d 舀n r

nginx图片缓存服务器配置文档

nginx图片缓存服务器配置文档

Nginx图片缓存服务器配置Nginx是目前非常流行的web服务器,它起源于俄罗斯。

它具有处理速度快,并发量大,占用资源极低等优点,尤其对于静态资源的处理更佳,有测试证明是apache的30倍。

现在已经广泛的应用于多家门户网站、中大型网站中,作为反向代理、图片缓存服务器等。

本例是结合张宴的blog(/nginx_cache/),做的变动。

主站是IIS7.5(192.168.36.70),用的是.net 3.5+sql 2005,用于处理aspx,ashx等动态网页程序,而网站的图片服务器为nginx(centos 5.6,IP:192.168.33.243).1.网站结构主站(iis 7.5)的网页结构为:注意:myimages目录,是nginx图片服务器的主目录,放到这里作为一个虚拟目录的原因,是在centos上做了一个samba,让windows共享到这个目录,方便主站.net程序对图片上传和管理。

更好的解决方案是,把所有的资源放到存储上。

Nginx图片服务器的目录结构为:注意:images是nginx服务器的主目录,images1和images2是图片服务器的分支目录,用于存放图片,更专业的做法,是用当前月份命名目录,更加方便管理图片。

proxy_cache_dir和proxy_temp_dir分别是作为nginx图片服务器的缓存目录和临时目录。

用户只要访问一次图片,nginx就会把图片缓存到proxy_cache_dir目录底下。

2.nginx图片服务器配置1. centos5.6上安装nginx.安装步骤如下:wget ftp:///pub/software/programming/pcre/pcre-8.00.tar.gztar zxvf pcre-8.00.tar.gzcd pcre-8.00/./configuremake && make installcd ../wget /files/ngx_cache_purge-1.0.tar.gztar zxvf ngx_cache_purge-1.0.tar.gzwget /download/nginx-0.8.32.tar.gztar zxvf nginx-0.8.32.tar.gzcd nginx-0.8.32/./configure --user=www --group=www --add-module=../ngx_cache_purge-1.0 --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_modulemake && make installcd ../注意:要建立www用户和www用户组2. 配置nginx的配置文件注意nginx的图片服务器访问地址为:192.168.33.243:8080,nginx缓存服务器为:192.168.33.243,故我们需要在Nginx上配置两个web服务器,让后一个缓存前一个,iis 主站的程序直接调用缓存服务器的图片,绕过了真实的图片服务器。

Nginx安装指南 - CentOS

Nginx安装指南 - CentOS

Nginx安装指南前言:本文所有操作,基于64位的CentOS6.5操作系统进行,使用的软件包括nginx-1.9.9、openssl-1.0.1、pcre-8.37、zlib-1.2.8安装服务支撑组件注意:安装前需要保证服务器上已安装gcc、gcc-c++、openssl-devel、popt-devel组件查询附件是否安装gcc -v如果没有安装,保证服务器可以联网,执行如下命令安装:yum install gccyum install gcc-c++yum -y install openssl-develyum install popt-devel -yNginx服务安装1、选定源码目录1)选定源码目录cd/usr/local2、安装pcre1)上传pcre文件将pcre-8.37.tar.gz上传到/usr/local目录,进入/usr/localcd /usr/local2)解压缩pcretar -xvf pcre-8.37.tar.gz3)进入解压目录cd pcre-8.374)配置pcre./configure如图所示,表示安装成功5)编译make如图所示,表示编译成功6)安装make install如图所示,表示安装成功3、安装openssl1)上传openssl文件将openssl-1.0.1c.tar.gz上传到/usr/local目录,进入/usr/local cd /usr/local2)解压缩openssltar -xvf openssl-1.0.1c.tar.gz3)进入解压目录cd openssl-1.0.1c4)配置openssl./config如图所示,表示安装成功5)编译make如图所示,表示编译成功6)安装make install如图所示,表示安装成功4、安装zlib1)上传zlib文件将zlib-1.2.8.tar.gz上传到/usr/local目录,进入/usr/local cd /usr/local2)解压缩zlibtar -xvf zlib-1.2.8.tar.gz3)进入解压目录cd zlib-1.2.84)配置zlib./configure如图所示,表示安装成功5)编译make如图所示,表示编译成功6)安装make install如图所示,表示安装成功5、安装Nginx1)上传Nginx文件将nginx-1.9.9.tar.gz上传到/usr/local目录,进入/usr/localcd /usr/local2)解压缩Nginxtar -xvf nginx-1.9.9.tar.gz3)进入解压目录cd nginx-1.9.94)配置Nginx./configure --prefix=/home/nginx/nginx--with-http_ssl_module如图所示,表示安装成功5)编译make如图所示,表示编译成功6)安装make install如图所示,表示安装成功6、配置Nginx1)进入nginx安装目录cd/home/nginx/nginx/conf2)设置反向代理和负载均衡i)编辑nginx.conf文件vinginx.confii)设置代理信息,将如下内容替换到nginx.conf文件中worker_processes 4; # 工作进程数,为CPU的核心数或者两倍error_log logs/error.log crit; # debug|info|notice|warn|error|critpid logs/nginx.pid;events {use epoll; #Linux最常用支持大并发的事件触发机制worker_connections 65535;}http {includemime.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;#设定请求缓冲server_names_hash_bucket_size 256; #增加,原为128client_header_buffer_size 256k; #增加,原为32klarge_client_header_buffers 4 256k; #增加,原为32k#size limitsclient_max_body_size 50m; #允许客户端请求的最大的单个文件字节数client_header_timeout 3m;client_body_timeout 3m;send_timeout 3m;sendfile on;tcp_nopush on;keepalive_timeout 120;tcp_nodelay on;server_tokens off; #不显示nginx版本信息limit_conn_zone $binary_remote_addr zone=perip:10m; #添加limit_zone,限制同一IP并发数#fastcgi_intercept_errors on; #开启错误页面跳转proxy_temp_path /tmp/proxy_temp;proxy_cache_path /tmp/proxy_cache levels=1:2 keys_zone=cache_one:500m inactive=1d max_size=3g;client_body_buffer_size 512k; #原为512kproxy_connect_timeout 50; #代理连接超时proxy_read_timeout 600; #代理发送超时proxy_send_timeout 600; #代理接收超时proxy_buffer_size 128k; #代理缓冲大小,原为32kproxy_buffers 16 256k; #代理缓冲,原为4 64kproxy_busy_buffers_size 512k; #高负荷下缓冲大小,原为128kproxy_temp_file_write_size 1024m; #proxy缓存临时文件的大小原为128k #proxy_ignore_client_abort on; #不允许代理端主动关闭连接proxy_next_upstream error timeout invalid_header http_500 http_503 http_404http_502 http_504;upstreamsmc{#ip_hash;server 10.40.129.160:18080;server 10.40.129.161:18080;}upstreamscc{server 10.40.129.160:28080;server 10.40.129.161:28080;}upstreamsi{server 10.40.129.160:38080;server 10.40.129.161:38080;}upstreamauth{server 10.40.129.160:48080;server 10.40.129.161:48080;}server {listen 18080;server_namelocalhost;location / {proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://smc;}}server {listen 28081;server_namelocalhost;location / {proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://scc;}error_page404 /404.html;error_page 500 502 503 504 /404.html;location = /404.html {root html;}limit_connperip 20000; #同一ip并发数为50,超过会返回503 }server {listen 38081;ssl on;ssl_certificate /home/nginx/nginx/conf/server.crt;ssl_certificate_key /home/nginx/nginx/conf/server_nopwd.key;server_namelocalhost;location / {proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://si;}#access_log off; #根据自己的需要选择是否启用access日志,注释掉代表启用error_page404 /404.html;error_page 500 502 503 504 /404.html;location = /404.html {root html;}limit_connperip 20000; #同一ip并发数为50,超过会返回503}server {listen 48081;server_namelocalhost;location / {proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://auth;}error_page404 /404.html;error_page 500 502 503 504 /404.html;location = /404.html {root html;}limit_connperip 20000; #同一ip并发数为50,超过会返回503}}7、配置Nginx开机自启动1)编辑配置文件vi /etc/rc.d/init.d/nginx2)在文件中添加如下内容#!/bin/bash# nginx Startup script for the Nginx HTTP Server# it is v.1.3.0 version.# chkconfig: - 85 15# description: Nginx is a high-performance web and proxy server.# It has a lot of features, but it's not for everyone.# processname: nginx# pidfile: /var/run/nginx.pid# config: /usr/local/nginx/conf/nginx.confnginxd=/usr/local/nginx/sbin/nginxnginx_config=/usr/local/nginx/conf/nginx.confnginx_pid=/usr/local/nginx/logs/nginx.pidRETVAL=0prog="nginx"# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ ${NETWORKING} = "no" ] && exit 0[ -x $nginxd ] || exit 0# Start nginx daemons functions.start() {if [ -e $nginx_pid ];thenecho "nginx already running...."exit 1fiecho -n $"Starting $prog: "daemon $nginxd -c ${nginx_config}RETVAL=$?echo[ $RETVAL = 0 ] && touch /var/lock/subsys/nginxreturn $RETVAL}# Stop nginx daemons functions.stop() {echo -n $"Stopping $prog: "killproc $nginxdRETVAL=$?echo[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid }reload() {echo -n $"Reloading $prog: "#kill -HUP `cat ${nginx_pid}`killproc $nginxd -HUPRETVAL=$?echo}# See how we were called.case "$1" instart)start;;stop)stop;;reload)reload;;restart)stopstart;;status)status $progRETVAL=$?;;*)echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1esacexit $RETVAL3)设置开机自启动权限chmod +x /etc/rc.d/init.d/nginxchkconfignginx on8、生成HTTPS证书1)生成HTTPS证书cd /home/nginx/nginx/confopensslgenrsa -des3 -out server.key 1024opensslreq -new -key server.key -out server.csropensslrsa -in server.key -out server_nopwd.keyopenssl x509 -req -days 365 -in server.csr -signkeyserver_nopwd.key -out server.crt 注意:生成过程需要输入密码,请根据实际情况输入9、启动Nginx1)进入Nginx服务cd/home/nginx/nginx/sbin2)启动Nginx服务./nginx3)验证启动结果ps -ef|grepnginx如图,表示启动成功10、安装Keepalived服务1)上传Keepalived文件将keepalived-1.2.7.tar.gz上传到/usr/local目录,进入/usr/local cd /usr/local2)解压缩Keepalivedtar -xvfkeepalived-1.2.7.tar.gz3)进入解压目录cdkeepalived-1.2.74)配置Keepalived./configure如图所示,表示安装成功5)编译make如图所示,表示编译成功6)安装make install如图所示,表示安装成功11、安装Keepalived服务1)配置Keepalived启动方式cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/cp /usr/local/etc/sysconfig/keepalived /etc/sysconfigmkdir /etc/keepalivedcp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/cp /usr/local/sbin/keepalived /usr/sbinchkconfigkeepalived on2)修改Keepalived配置文件vi /etc/keepalived/keepalived.conf将文件内容修改为如下内容! Configuration File for keepalivedvrrp_script chk_http_port {script "/etc/keepalived/nginx_pid.sh" # 检查nginx状态的脚本interval 2weight 3}vrrp_instance VI_1 {state MASTER #备服务器设置为BACKUPinterface eth0 #eth0 是否存在,请根据实际安装环境检测,以#网卡实际信息为准,如eth1。

Centos8安装nginx-nginx反向代理及13Permission denied报错,以及selinux设置

Centos8安装nginx-nginx反向代理及13Permission denied报错,以及selinux设置


proxy_connect_timeout 30000s;#nginx跟后端服务器连接超时时间(代理连接超时)

proxy_send_timeout 300000s;#后端服务器数据回传时间(代理发送超时)

proxy_read_timeout 300000s;#连接成功后,后端服务器响应时间(代理接收超时)
• semodule -i mynginx.pp
感谢您的观看 THANKS
常用目录
• Nginx配置文件:/etc/nginx/nginx.conf
• Error文件:/var/log/nginx/error.log
CONTENTS
02Part Two Nginx设置
编辑Nginx.conf设置反向代理内容
反向代理详细注释内容
反向代理详细注释内容1
• #nginx进程数,建议设置为等于CPU总核心数。
重新启动还报错
查看error
重新编辑nginx.conf
缺少两个}}
• 报错原因找了好久最后发现是selinux的原因
CONTENTS
04Part Four selinux设置
• 使用这个命令就可以查看相关的信息了
• cat /var/log/audit/audit.log | grep nginx | grep denied
CONTENTS
01Part One 安装Nginx
• Nginx发音为“ engine x”,是一种开源的高 性能HTTP和反向代理服务器,负责处理 Internet上一些最大站点的负载。它可用作 HTTP和非HTTP服务器的独立Web服务器, 负载平衡器,内容缓存和反向代理。
• 与Apache相比,Nginx可以处理大量并发连 接,并且每个连接的内存占用量较小。

CentOS7源码安装Nginx

CentOS7源码安装Nginx

CentOS7源码安装Nginx系统平台:腾讯云服务器CentOS7.364位一、安装编译工具及库文件[root@VM_0_5_centos~]#yum install-y make zlib zlib-devel gcc-c++libtool openssl openssl-devel二、安装pcrePCRE作用是让Nginx支持Rewrite功能。

1、下载PCRE包[root@VM_0_5_centos~]#cd/usr/local/src/[root@VM_0_5_centos src]#wget /project/pcre/pcre/8.35/pcre-8.35.tar.gz2、解压安装包[root@VM_0_5_centos src]#tar zxvf pcre-8.35.tar.gz3、进入解压后安装包目录[root@VM_0_5_centos src]#cd pcre-8.354、编译安装[root@VM_0_5_centos pcre-8.35]#./configure[root@VM_0_5_centos pcre-8.35]#make[root@VM_0_5_centos pcre-8.35]#make install5、查看pcre版本[root@VM_0_5_centos pcre-8.35]#pcre-config--version8.35三、安装Nginx1、下载Nginx[root@VM_0_5_centos~]#cd/usr/local/src/[root@VM_0_5_centos src]#wget /download/nginx-1.16.0.tar.gz2、解压安装包[root@VM_0_5_centos src]#tar zxvf nginx-1.16.0.tar.gz3、进入解压后的目录[root@VM_0_5_centos src]#cd nginx-1.16.04、编译安装[root@VM_0_5_centos nginx-1.16.0]#./configure--prefix=/usr/local/nginx--with-http_stub_status_module--with-http_ssl_module--with-pcre=/usr/local/src/pcre-8.35 [root@VM_0_5_centos nginx-1.16.0]#make[root@VM_0_5_centos nginx-1.16.0]#make install--prefix指定安装路径5、查看nginx版本[root@VM_0_5_centos nginx-1.16.0]#/usr/local/nginx/sbin/nginx-vnginx version:nginx/1.16.0四、Nginx配置创建Nginx运行使用的用户www[root@VM_0_5_centos~]#groupadd www[root@VM_0_5_centos~]#useradd-g www www修改配置文件[root@VM_0_5_centos~]#vim/usr/local/nginx/conf/nginx.confuser www www;#指定用户名和组名worker_processes1;#设置值和cpu核心数一致error_log error_log error_log pidevents{logs/error.log;logs/error.log notice; logs/error.log info; logs/nginx.pid;worker_connections}http{1024;include default_type mime.types;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_logsendfile tcp_nopush logs/access.logon;on;main;#keepalive_timeout0; keepalive_timeout60; #gzip on;server{listenserver_name 80; localhost;#charset koi8-r;#access_log logs/host.access.log main;location/{root html;index index.html index.htm;}#error_page404/404.html;#redirect server error pages to the static page/50x.html#error_page500502503504/50x.html;location=/50x.html{root html;}#proxy the PHP scripts to Apache listening on127.0.0.1:80##location~\.php${#proxy_pass http://127.0.0.1;#}#pass the PHP scripts to FastCGI server listening on127.0.0.1:9000##location~\.php${#root html;#fastcgi_pass127.0.0.1:9000;#fastcgi_index index.php;#fastcgi_param SCRIPT_FILENAME/scripts$fastcgi_script_name;#include fastcgi_params;#}#deny access to.htaccess files,if Apache's document root#concurs with nginx's one##location~/\.ht{#deny all;#}}#another virtual host using mix of IP-,name-,and port-based configuration ##server{#listen#listen#server_name 8000;somename:8080;somename alias another.alias;# # # #location/{root html;index index.html index.htm; }#}#HTTPS server ##server{#listen#server_name 443ssl; localhost;# # # #ssl_certificatessl_certificate_keyssl_session_cachessl_session_timeoutcert.pem;cert.key;shared:SSL:1m;5m;# # # # # # #}ssl_ciphers HIGH:!aNULL:!MD5;ssl_prefer_server_ciphers on;location/{root html;index index.html index.htm; }}后续根据需要配置;检查配置文件nginx.conf的正确性命令:[root@VM_0_5_centos conf]#/usr/local/nginx/sbin/nginx-tnginx:the configuration file/usr/local/nginx/conf/nginx.conf syntax is ok nginx:configuration file/usr/local/nginx/conf/nginx.conf test is successful 五、启动Nginx[root@VM_0_5_centos conf]#/usr/local/nginx/sbin/nginx六、Nginx其他查用命令[root@VM_0_5_centos conf]#/usr/local/nginx/sbin/nginx-s reload [root@VM_0_5_centos conf]#/usr/local/nginx/sbin/nginx-s reopen [root@VM_0_5_centos conf]#/usr/local/nginx/sbin/nginx-s stop #重新载入配置文件#重启Nginx#停止nginx。

Nginx搭建(完整版)

Nginx搭建(完整版)

目录1搭建nginx需要的安装包-----------------------------------------------------------------------2 2前期准备--------------------------------------------------------------------------------------------22.1 检测-----------------------------------------------------------------------------------------22.2安装libiconv-1.13--------------------------------------------------------------------------22.3安装libmcrypt-2.5.8.----------------------------------------------------------------------22.4安装mhash-0.9.9.9-------------------------------------------------------------------------22.5安装mcrypt-2.6.8--------------------------------------------------------------------------33安装mysql------------------------------------------------------------------------------------------3 3.1创建用户和组--------------------------------------------------------------------------------3 3.2安装编译--------------------------------------------------------------------------------------3 3.3创建MySQL数据库存放目录------------------------------------------------------------3 3.4创建f配置文件-----------------------------------------------------------------------3 3.5创建管理MySQL数据库的shell脚本---------------------------------------------------5 3.6创建账户,赋予关闭的权限----------------------------------------------------------------6 4安装编译php----------------------------------------------------------------------------------------6 4.1 编译php---------------------------------------------------------------------------------------6 4.2编译安装PHP扩展模块--------------------------------------------------------------------74.2.1编译memcache--------------------------------------------------------------------------74.2.2编译eaccelerator-0.9.5.3--------------------------------------------------------------74.2.3编译PDO_MYSQL-1.0.2-------------------------------------------------------------74.2.4编译ImageMagick----------------------------------------------------------------------74.2.5编译imagick-2.2.2-----------------------------------------------------------------------74.3 修改php配置文件------------------------------------------------------------------------74.4配置eAccelerator加速PHP--------------------------------------------------------------84.5创建www用户和组------------------------------------------------------------------------84.6创建虚拟机目录-----------------------------------------------------------------------------84.7创建php-fpm配置文件--------------------------------------------------------------------84.8启动php-cgi进程---------------------------------------------------------------------------12 5安装编译nginx-----------------------------------------------------------------------------------125.1安装Nginx所需的pcre库---------------------------------------------------------------125.2安装Nginx----------------------------------------------------------------------------------125.3建Nginx配置文件-------------------------------------------------------------------------125.4启动Nginx-----------------------------------------------------------------------------------125.5配置开机自动启动Nginx + PHP--------------------------------------------------------135.6优化Linux内核参数-----------------------------------------------------------------------135.7在不停止Nginx服务的情况下平滑变更Nginx配置--------------------------------135.7.1检查配置文件---------------------------------------------------------------------------135.7.2 nginx进程--------------------------------------------------------------------------------145.8编写每天定时切割Nginx日志的脚本---------------------------------------------------145.8.1创建脚本---------------------------------------------------------------------------------145.8.2添加自动任务----------------------------------------------------------------------------146 安装编译memcached-------------------------------------------------------------------------------156.1 安装编译libevent-----------------------------------------------------------------------------156.2 安装编译memcached------------------------------------------------------------------------156.3 启动memcached守护进程-----------------------------------------------------------------156.4 php使用测试--------------------------------------------------------------------------------156.5 停止memcached服务-----------------------------------------------------------------------151、搭建nginx需要的安装包放在219.234.83.29服务器上cd /home/chenjl/software/nginx0.8_basepacage2、前期准备2.1需要安装一些常用的包,在安装服务器时选择安装开发工具,会安装一些常用的包,如果安装了yum,可以用检测一下(【适用CentOS操作系统】)yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers2.2安装libiconv-1.13.tar.gztar zxvf libiconv-1.13.tar.gzcd libiconv-1.13/./configure --prefix=/usr/localmakemake install2.3安装libmcrypt-2.5.8.tar.gztar zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8/./configuremakemake install/sbin/ldconfigcd libltdl/./configure --enable-ltdl-installmakemake install2.4安装mhash-0.9.9.9.tar.gztar zxvf mhash-0.9.9.9.tar.gzcd mhash-0.9.9.9/./configuremakemake installln -s /usr/local/lib/ /usr/lib/ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.soln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.aln -s /usr/local/lib/ /usr/lib/ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.soln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.12.5安装mcrypt-2.6.8.tar.gztar zxvf mcrypt-2.6.8.tar.gzcd mcrypt-2.6.8//sbin/ldconfig./configuremakemake install3、安装mysql3.1 创建用户和组/usr/sbin/groupadd mysql/usr/sbin/useradd -g mysql mysql3.2 安装编译tar zxvf mysql-5.1.38.tar.gzcd mysql-5.1.38/./configure --prefix=/usr/local/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobasemake && make installchmod +w /usr/local/mysqlchown -R mysql:mysql /usr/local/mysqlmkdir -p /usr/local/mysqldata/3.3创建MySQL数据库存放目录chown -R mysql:mysql /usr/local/mysql/data//usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql /data --user=mysql3.4创建f配置文件输入以下内容:###############################[client]default-character-set = utf8port = 3306socket = /tmp/mysql.sock[mysql]prompt="(\u::)[\d]> "no-auto-rehash[mysqld]#default-character-set = utf8user = mysqlport = 3306socket = /tmp/mysql.sockbasedir = /usr/local/mysqldatadir = /usr/local/mysql/dataopen_files_limit = 10240back_log = 600max_connections = 3000max_connect_errors = 6000table_cache = 614external-locking = FALSEmax_allowed_packet = 32Msort_buffer_size = 2Mjoin_buffer_size = 2Mthread_cache_size = 300thread_concurrency = 8query_cache_size = 32Mquery_cache_limit = 2Mquery_cache_min_res_unit = 2kdefault-storage-engine = MyISAMdefault_table_type = MyISAMthread_stack = 192Ktransaction_isolation = READ-COMMITTED tmp_table_size = 246Mmax_heap_table_size = 246Mlong_query_time = 1log_long_formatlog-bin = /data0/mysql/3306/binlogbinlog_cache_size = 4Mbinlog_format = MIXEDmax_binlog_cache_size = 8Mmax_binlog_size = 512Mexpire_logs_days = 7key_buffer_size = 256Mread_buffer_size = 1Mread_rnd_buffer_size = 16Mbulk_insert_buffer_size = 64Mmyisam_sort_buffer_size = 128Mmyisam_max_sort_file_size = 10Gmyisam_max_extra_sort_file_size = 10G myisam_repair_threads = 1myisam_recoverskip-name-resolvemaster-connect-retry = 10slave-skip-errors = 1032,1062,126,1114,1146,1048,1396server-id = 1innodb_additional_mem_pool_size = 16Minnodb_buffer_pool_size = 2048Minnodb_data_file_path = ibdata1:1024M:autoextendinnodb_file_io_threads = 4innodb_thread_concurrency = 8innodb_flush_log_at_trx_commit = 2innodb_log_buffer_size = 16Minnodb_log_file_size = 128Minnodb_log_files_in_group = 3innodb_max_dirty_pages_pct = 90innodb_lock_wait_timeout = 120innodb_file_per_table = 0[mysqldump]quickmax_allowed_packet = 32M以上数据,根据需要做修改;3.5创建管理MySQL数据库的shell脚本#!/bin/shmysql_port=3306mysql_username="chenjl"mysql_password="cjl1981"function_start_mysql(){printf "Starting MySQL...\n"/bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/f 2>&1 > /dev/null &}function_stop_mysql(){printf "Stoping MySQL...\n"/usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /tmp/mysql.sock shutdown}function_restart_mysql(){printf "Restarting MySQL...\n"function_stop_mysqlsleep 5function_start_mysql}function_kill_mysql(){kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{printf $2}')kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port} | awk '{printf $2}')}if [ "$1" = "start" ]; thenfunction_start_mysqlelif [ "$1" = "stop" ]; thenfunction_stop_mysqlelif [ "$1" = "restart" ]; thenfunction_restart_mysqlelif [ "$1" = "kill" ]; thenfunction_kill_mysqlelseprintf "Usage: /data0/mysql/${mysql_port}/mysql {start|stop|restart|kill}\n"fichmod 755 /usr/local/mysql/bin/mysql.sh3.6 创建账户,赋予关闭的权限/usr/local/mysql/bin/mysql -u root -p -S /tmp/mysql.sockGRANT ALL PRIVILEGES ON *.* TO 'chenjl'@'localhost' IDENTIFIED BY 'cjl1981';GRANT ALL PRIVILEGES ON *.* TO 'chenjl'@'127.0.0.1' IDENTIFIED BY 'cjl1981;4、安装编译php4.1 编译phptar zxvf php-5.2.10.tar.gzgzip -cd php-5.2.10-fpm-0.5.11.diff.gz | patch -d php-5.2.10 -p1cd php-5.2.10/./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pearmake ZEND_EXTRA_LIBS='-liconv'make installcp php.ini-dist /usr/local/php/etc/php.inicurl /go-pear | /usr/local/php/bin/php4.2编译安装PHP扩展模块4.2.1 编译memcachetar zxvf memcache-2.2.5.tgzcd memcache-2.2.5//usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-configmakemake install启动方式:/usr/local/bin/memcached -d -m 64 -u root -l 127.0.0.1 -p 11211 -c 1024 -P /tmp/memcached.pid4.2.2 编译eaccelerator-0.9.5.3tar jxvf eaccelerator-0.9.5.3.tar.bz2cd eaccelerator-0.9.5.3//usr/local/php/bin/phpize./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-configmakemake install4.2.3编译PDO_MYSQL-1.0.2tar zxvf PDO_MYSQL-1.0.2.tgzcd PDO_MYSQL-1.0.2//usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysqlmakemake install4.2.4编译ImageMagicktar zxvf ImageMagick.tar.gzcd ImageMagick-6.5.1-2/./configure tar zxvf imagick-2.2.2.tgzmakemake instal4.2.5 编译imagick-2.2.2tar zxvf imagick-2.2.2.tgzcd imagick-2.2.2//usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-configmakemake install4.3 修改php配置文件手工修改:查找/usr/local/php/etc/php.ini中的extension_dir = "./"修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"并在此行后增加以下几行,然后保存:extension = "memcache.so"extension = "pdo_mysql.so"extension = "imagick.so"再查找output_buffering = Off修改为output_buffering = On4.4配置eAccelerator加速PHPmkdir -p /usr/local/eaccelerator_cachevi /usr/local/php/etc/php.ini按shift+g键跳到配置文件的最末尾,加上以下配置信息:[eaccelerator]zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eacceler ator.so"eaccelerator.shm_size="64"eaccelerator.cache_dir="/usr/local/eaccelerator_cache"eaccelerator.enable="1"eaccelerator.optimizer="1"eaccelerator.check_mtime="1"eaccelerator.debug="0"eaccelerator.filter=""eaccelerator.shm_max="0"eaccelerator.shm_ttl="3600"eaccelerator.shm_prune_period="3600"eaccelerator.shm_only="0"press="1"press_level="9"4.5创建www用户和组usr/sbin/groupadd www/usr/sbin/useradd -g www www4.6创建虚拟机目录Mkdir /usr/local/wwwChown –R www:www /usr/local/www4.7创建php-fpm配置文件<?xml version="1.0" ?><configuration>All relative paths in this config are relative to php's install prefix<section name="global_options">Pid file<value name="pid_file">/usr/local/php/logs/php-fpm.pid</value>Error log file<value name="error_log">/usr/local/php/logs/php-fpm.log</value>Log level<value name="log_level">notice</value>When this amount of php processes exited with SIGSEGV or SIGBUS ...<value name="emergency_restart_threshold">10</value>... in a less than this interval of time, a graceful restart will be initiated.Useful to work around accidental curruptions in accelerator's shared memory. <value name="emergency_restart_interval">1m</value>Time limit on waiting child's reaction on signals from master<value name="process_control_timeout">5s</value>Set to 'no' to debug fpm<value name="daemonize">yes</value></section><workers><section name="pool">Name of pool. Used in logs and stats.<value name="name">default</value>Address to accept fastcgi requests on.Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'<value name="listen_address">127.0.0.1:9000</value><value name="listen_options">Set listen(2) backlog<value name="backlog">-1</value>Set permissions for unix socket, if one used.In Linux read/write permissions must be set in order to allow connections from web server.Many BSD-derrived systems allow connections regardless of permissions.<value name="owner"></value><value name="group"></value><value name="mode">0666</value></value>Additional php.ini defines, specific to this pool of workers.<value name="php_defines"><value name="sendmail_path">/usr/sbin/sendmail -t -i</value><value name="display_errors">1</value></value>Unix user of processes<value name="user">www</value>Unix group of processes<value name="group">www</value>Process manager settings<value name="pm">Sets style of controling worker process count.Valid values are 'static' and 'apache-like'<value name="style">static</value>Sets the limit on the number of simultaneous requests that will be served.Equivalent to Apache MaxClients directive.Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgiUsed with any pm_style.<value name="max_children">128</value>Settings group for 'apache-like' pm style<value name="apache_like">Sets the number of server processes created on startup.Used only when 'apache-like' pm_style is selected<value name="StartServers">20</value>Sets the desired minimum number of idle server processes.Used only when 'apache-like' pm_style is selected<value name="MinSpareServers">5</value>Sets the desired maximum number of idle server processes.Used only when 'apache-like' pm_style is selected<value name="MaxSpareServers">35</value></value></value>The timeout (in seconds) for serving a single request after which the worker process will be terminatedShould be used when 'max_execution_time' ini option does not stop script execution for some reason'0s' means 'off'<value name="request_terminate_timeout">0s</value>The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file'0s' means 'off'<value name="request_slowlog_timeout">0s</value>The log file for slow requests<value name="slowlog">logs/slow.log</value>Set open file desc rlimit<value name="rlimit_files">65535</value>Set max core size rlimit<value name="rlimit_core">0</value>Chroot to this directory at the start, absolute path<value name="chroot"></value>Chdir to this directory at the start, absolute path<value name="chdir"></value>Redirect workers' stdout and stderr into main error log.If not set, they will be redirected to /dev/null, according to FastCGI specs<value name="catch_workers_output">yes</value>How much requests each process should execute before respawn.Useful to work around memory leaks in 3rd party libraries.For endless request processing please specify 0Equivalent to PHP_FCGI_MAX_REQUESTS<value name="max_requests">102400</value>Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+) Makes sense only with AF_INET listening socket.<value name="allowed_clients">127.0.0.1</value>Pass environment variables like LD_LIBRARY_PATHAll $V ARIABLEs are taken from current environment<value name="environment"><value name="HOSTNAME">$HOSTNAME</value><value name="PATH">/usr/local/bin:/usr/bin:/bin</value><value name="TMP">/tmp</value><value name="TMPDIR">/tmp</value><value name="TEMP">/tmp</value><value name="OSTYPE">$OSTYPE</value><value name="MACHTYPE">$MACHTYPE</value><value name="MALLOC_CHECK_">2</value></value></section></workers></configuration>注:请将以下的<value name="display_errors">0</value>改为<value name="display_errors">1</value>,以便显示PHP错误信息,否则,Nginx 会报状态为500的空白错误页)4.8启动php-cgi进程,监听127.0.0.1的9000端口,进程数为200(如果服务器内存小于3GB,可以只开启64个进程),用户为www:ulimit -SHn 65535/usr/local/php/sbin/php-fpm start注:/usr/local/php/sbin/php-fpm还有其他参数,包括:start|stop|quit|restart|reload|logrotate,修改php.ini后不重启php-cgi,重新加载配置文件使用reload。

nginx实现网站图片上载服务器

nginx实现网站图片上载服务器

我这里就写两个例子:Eg1:电商网站分前台和后台,后台维护商品和供应商即后台上传图片前台展示,现在要求前台部署在A服务器,前台部署在B服务器上且用nginx做图片服务器并将nginx服务装在A服务器上,图片上传到A服务器本地xx文件夹下。

这中情况就很简单,我们只需要将后台上传图片的url设置为A服务本地创建的xx文件,并修改conf/nginx.conf中server {listen 80;server_name 127.0.0.1;#charset koi8-r;#access_log logs/host.access.log main;location /ekaImage/{alias D:\ekaImage;}前台访问时直接http://A服务IP: ekaImage/XX/xx.jpg即可Eg2:后台服务部署在A服务器上,前台部署在B服务器,图片服务器部署在C服务器上我们是单独将图片上传写了个APP部署在C服务器然后后台上传图片是调C服务器部署的图片服务器应用提供的上传图片的方法并将图片存放在C服务器的本地文件夹xxx下且在nginx.conf里修改为C服务器IP,前台访问时直接按http:+C服务器IP+文件路径+图片路径图片服务器应用:package com.nginx.service;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.util.Iterator;import java.util.List;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import mons.fileupload.FileItem;import mons.fileupload.FileItemFactory;importmons.fileupload.FileUploadException; importmons.fileupload.disk.DiskFileItemFactor y;importmons.fileupload.servlet.ServletFileUplo ad;import org.apache.log4j.Logger;/*** Servlet implementation class nginxServlet*/public class nginxServlet extends HttpServlet {private Logger logger=Logger.getLogger(nginxServlet.class);private static final long serialVersionUID = 1L;/*** @see HttpServlet#HttpServlet()*/public nginxServlet() {super();(" nginxServlet init .......... "); }/*** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {(" nginxServletdoGet ............................ ");doPost(request,response);}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {(" nginxServletdoPost ............................ ");FileItemFactory factory = newDiskFileItemFactory();ServletFileUpload upload = newServletFileUpload(factory);try {List items = upload.parseRequest(request); Iterator iter = items.iterator();while (iter.hasNext()) {FileItem item = (FileItem) iter.next();if (item.isFormField()) {//普通文本信息处理String paramName =item.getFieldName();String paramValue = item.getString();(paramName + ":" + paramValue);} else {//上传文件信息处理String fileName = item.getName(); String filePath="";if(fileName.indexOf("/")!=-1){filePath =fileName.substring(0,stIndexOf("/"));fileName =fileName.substring(stIndexOf("/"),fileName.length());}("item :"+item.getName());(" fname : "+fileName);(" path : "+filePath);File f = new File(filePath);if(!f.exists()){f.mkdirs();}byte[] data = item.get();FileOutputStream fos = newFileOutputStream(item.getName());fos.write(data);fos.close();}}} catch (FileUploadException e) {logger.error(" nginxServlet doPOST exception :"+e.getMessage());e.printStackTrace();}}}Web.xml:<servlet><description></description><display-name>nginxServlet</display-name><servlet-name>nginxServlet</servlet-name><servlet-class>com.nginx.service.nginxServlet</servle t-class></servlet><servlet-mapping><servlet-name>nginxServlet</servlet-name><url-pattern>/nginxServlet</url-pattern></servlet-mapping>配置nginx/nginx.confserver {listen 80;server_name 127.0.0.1;#charset koi8-r;#access_log logs/host.access.log main;location /ekaImage/{alias /wls/ekaImage/;}后台服务代码:#图片服务器imgIp= http://192.168.221.91/ekaImage前台<imgsrc=”${ imgIp }”>#图片上传到哪个地方uploadFilePath = /wls/ekaImage/#nginx图片服务器应用Nginxpath=http://192.168.221.91:8080/nginxService/ngi nxServlet后台上传图片调图片服务器http://192.168.221.91:8080/nginxService/nginxServlet 如service:@RequestMapping(value = "uploadFile")@ResponseBodypublic Map<String,Object>uploadFile(MultipartHttpServletRequest request, HttpServletResponse response, String type) throws IOException{Map<String,Object> map = new HashMap<String, Object>();SimpleDateFormat dateformat = new SimpleDateFormat("yyyy/MM/dd/HH");try {MultipartHttpServletRequest multipartRequest = request;MultipartFile file =multipartRequest.getFile("file");String fileName = file.getOriginalFilename();String suffix =fileName.substring(stIndexOf("."));String destFileName = new Date().getTime() + suffix;InputStream stream = file.getInputStream();//Nginx 图片服务器地址String serverPath =PropertiesUtil.getValue("nginxpath");String path =PropertiesUtil.getValue("uploadFilePath")+ dateformat.format(new Date());upload(serverPath,file.getInputStream(),path,destFi leName);("-----------path--------------"+path);String logoRealPathDir = path;("-----------logoRealPathDir 2--------------"+logoRealPathDir);String returnPath = logoRealPathDir +"/" + destFileName;map.put("status", "ok");map.put("filePath", returnPath);map.put("fileName", fileName);} catch (Exception e) {logger.error("文件上传失败或者json.put值失败,失败信息:" + e);try {map.put("status", "fail");} catch (JSONException e2) {logger.error("json.put值失败,失败信息:" + e2);}}return map;}。

【最新精选】centos7安装fastdfsnginxmodule

【最新精选】centos7安装fastdfsnginxmodule

Centos7 安装FastDFS+nginx module1,关于FastDFS摘自:/p/fastdfsFastDFS是一个开源的分布式文件系统,她对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。

特别适合以文件为载体的在线服务,如相册网站、视频网站等等。

FastDFS服务端有两个角色:跟踪器(tracker)和存储节点(storage)。

跟踪器主要做调度工作,在访问上起负载均衡的作用。

存储节点存储文件,完成文件管理的所有功能:存储、同步和提供存取接口,FastDFS同时对文件的meta data进行管理。

所谓文件的meta data就是文件的相关属性,以键值对(key value pair)方式表示,如:width=1024,其中的key为width,value为1024。

文件meta data是文件属性列表,可以包含多个键值对。

GitHub:https:///happyfish100/fastdfs2,安装FastDFS参考文档:https:///happyfish100/fastdfs/blob/master/INSTALL2.1,安装编译工具2.2,安装libfastcommon类库2.3,安装FastDFS2.4,启动FastDFS启动:/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start修改配置文件:/etc/fdfs/storage.conf,修改路径到/data/fdfs目录,同时配置tracker_server地/usr/bin/fdfs_storaged /etc/fdfs/storage.conf start2.5 安装nginx + lua + fastdfs module 下载fastdfs-nginx-module模编译安装:这里注意下,需要增加参数。

NGINX服务器配置与优化指南

NGINX服务器配置与优化指南

NGINX服务器配置与优化指南第1章 NGINX基础概念与安装 (3)1.1 NGINX简介 (3)1.2 安装NGINX (3)1.2.1 在Debian/Ubuntu系统上安装 (3)1.2.2 在Red Hat/CentOS系统上安装 (3)1.2.3 在macOS上安装 (3)1.3 配置文件结构介绍 (4)第2章基本配置与启动 (4)2.1 配置语法规则 (4)2.2 配置指令概述 (5)2.3 启动、停止与重启NGINX (5)第3章虚拟主机配置 (6)3.1 基于IP的虚拟主机 (6)3.2 基于端口的虚拟主机 (6)3.3 基于域名的虚拟主机 (7)第4章 Location匹配规则 (8)4.1 location指令用法 (8)4.2 正则表达式匹配 (8)4.3 常用匹配规则案例 (9)第5章文件处理与缓存 (10)5.1 静态文件处理 (10)5.1.1 静态文件路径配置 (10)5.1.2 文件类型处理 (10)5.1.3 文件压缩 (10)5.1.4 expires缓存 (10)5.2 文件缓存配置 (10)5.2.1 开启open_file_cache (10)5.2.2 开启open_file_cache_errors (10)5.2.3 开启proxy_cache (10)5.3 expires指令使用 (11)5.3.1 expires指令参数 (11)5.3.2 expires配置示例 (11)第6章反向代理与负载均衡 (11)6.1 反向代理原理与配置 (11)6.1.1 反向代理概述 (11)6.1.2 反向代理的工作原理 (11)6.1.3 NGINX反向代理配置 (11)6.2 负载均衡策略 (12)6.2.1 轮询(Round Robin) (12)6.2.2 最少连接(Least Connections) (12)6.2.3 IP哈希(IP Hash) (12)6.2.4 加权负载均衡 (12)6.3 负载均衡的高级配置 (13)6.3.1 健康检查 (13)6.3.2 负载均衡器故障转移 (13)6.3.3 会话保持 (13)6.3.4 动态负载均衡 (13)第7章 SSL/TLS配置与优化 (13)7.1 SSL/TLS基础概念 (13)7.2 证书与私钥配置 (14)7.3 SSL优化与安全增强 (14)第8章功能优化与压力测试 (15)8.1 功能优化策略 (15)8.1.1 系统层面优化 (15)8.1.2 NGINX配置优化 (15)8.1.3 缓存策略优化 (16)8.2 压力测试工具介绍 (16)8.2.1 Apache Bench (ab) (16)8.2.2 YSlow (16)8.2.3 JMeter (16)8.2.4 LoadRunner (16)8.3 功能调优案例分析 (16)第9章安全性与防护 (17)9.1 常见攻击类型与防护策略 (17)9.1.1 DDoS攻击 (17)9.1.2 SQL注入攻击 (17)9.1.3 XSS攻击 (17)9.2 配置安全头部 (18)9.2.1 HTTP Strict Transport Security(HSTS) (18)9.2.2 Content Security Policy(CSP) (18)9.2.3 XContentTypeOptions (18)9.2.4 XFrameOptions (18)9.3 限制请求速率与连接数 (18)9.3.1 限制请求速率 (18)9.3.2 限制连接数 (19)第10章监控与故障排查 (19)10.1 监控工具与指标 (19)10.1.1 监控工具 (19)10.1.2 关键指标 (19)10.2 日志分析 (20)10.2.1 日志类型 (20)10.2.2 分析方法 (20)10.3 常见故障排查方法与技巧 (20)第1章 NGINX基础概念与安装1.1 NGINX简介NGINX(发音为“EngineX”)是一个高功能的HTTP和反向代理服务器,同时也用于邮件(IMAP/POP3/SMTP)代理服务器。

nginx代理图片上传以及访问nginx图片上传完整版

nginx代理图片上传以及访问nginx图片上传完整版

nginx代理图⽚上传以及访问nginx图⽚上传完整版nginx代理图⽚上传⾸先需要利⽤nginx代理图⽚访问参考编写接受⽂件的controller1 @PostMapping("image")2 public ResponseEntity<String> uploadImage(MultipartFile file){34 String url = null;5 try {6 url = uploadService.uploadImages(file);7 } catch (IOException e) {8 e.printStackTrace();9 }10 if (StringUtils.isBlank(url)){11 return ResponseEntity.status(HttpStatus.CREATED).build();12 }1314 return ResponseEntity.ok(url);15 }编写上传⽂件的service⽩名单参照:1 //创建⽂件上传类型⽩名单2 private static final List<String> CONTENT_TYPE = Arrays.asList("image/jpeg", "image/gif");3 //创建⽇志常量对象4 private static final Logger LOGGER = LoggerFactory.getLogger(UploadServiceImpl.class);56 /**7 * ⽂件上传⽅法8 *9 * @param file10 * @return11 */12 @Override13 public String uploadImages(MultipartFile file) {1415 //判断是否为图⽚⽂件16 //获取⽂件名17 String originalFilename = file.getOriginalFilename();18 //获取⽂件上传类型19 String contentType = file.getContentType();20 //判断是否为⽩名单中的类型21 if (!CONTENT_TYPE.contains(contentType)) {22 //输出⽇志为什么错误1.创建⽇志常量2.输出原因23 ("⽂件类型不合法 {}", originalFilename);24 return null;25 }26 //判断⽂件内容27 try {28 BufferedImage bufferedImage = ImageIO.read(file.getInputStream());29 if (bufferedImage != null) {30 //保存31 file.transferTo(new File("E:\\image\\" + originalFilename));32 }33 //返回访问路径34 return "/" + originalFilename;35 } catch (IOException e) {36 e.printStackTrace();37 }38 return null;39 }测试上传⽂件-->此处使⽤Advanced Rest Application测试⽤返回路径测试是否可以访问当前上传的图⽚/IMG_20180614_134202.jpg访问成功。

解析阿里云centos7服务器nginx配置及常见问题解答

解析阿里云centos7服务器nginx配置及常见问题解答

解析阿⾥云centos7服务器nginx配置及常见问题解答前⾔:1.make[1]: *** [objs/Makefile:473: objs/src/core/ngx_murmurhash.o] Error 12.make[1]: *** [objs/Makefile:774: objs/src/os/unix/ngx_user.o] Error 13.make[1]: *** [objs/Makefile:769: objs/src/event/ngx_event_openssl.o] Error 1本⽂针对这些问题和⼀些其他问题的解决⽅案都进⾏了阐述和流程上的改良内容流程:0.前置说明,1.安装gcc环境,2.安装pcre库,3.安装ssl库,4.安装zlib库,5.安装nginx,附:nginx在make过程中可能出现的问题,6.nginx启动与使⽤,7.nginx启动后⽆法访问的问题解决具体内容:0.前置说明在centos系统中,yum源不直接提供nginx的安装,因此可以通过切换yum源的⽅法进⾏nginx的安装,也可以通过直接下载依赖库和nginx安装包的⽅法来实现,本⽂介绍的是后者。

⼀些必要的库和nginx的关系:nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库然后本⽂将选定/usr/local为安装⽬录,⼀些库的具体版本号各位可根据实际改变,但由于互相依赖,所以最新的可能存在⼀些问题,谨慎选择。

且以下命令均需在root权限下执⾏1.安装gcc gcc-c++(如新环境,未安装请先安装)$ yum install -y gcc gcc-c++2.安装pcre库$ cd /usr/local/$ wget https:///projects/pcre/files/pcre/8.36/pcre-8.36.tar.gz(注:pcre版本会实时更新,8.36版本同样是旧版本,如果需要最新版本⾃⾏搜索pcre即可,然后选择新版本,不过新版本可能会不太稳定,需要注意。

centos服务器中配置nginx的方法示例

centos服务器中配置nginx的方法示例

centos服务器中配置nginx的⽅法⽰例下载安全终端MobaXterm_Personal⾸先,下载安全终端后,连接到⾃已的公⽹IP连接成功后显⽰如以上.Nginx简介Nginx是⼀款轻量级的⽹页服务器、反向代理服务器。

相较于Apache、lighttpd具有占有内存少,稳定性⾼等优势。

它最常的⽤途是提供反向代理服务连接上服务器后第⼀步:安装gcc gcc-c++命令为:yum install -y gcc gcc-c++第⼆步:安装PCRE库$ cd /usr/local/$ wget /project/pcre/pcre/8.33/pcre-8.33.tar.gz$ tar -zxvf pcre-8.36.tar.gz$ cd pcre-8.36$ ./configure$ make && make install如报错:configure: error: You need a C++ compiler for C++ support解决:yum install -y gcc gcc-c++第三步:安装SSL库$ cd /usr/local/$ wget /source/openssl-1.0.1j.tar.gz$ tar -zxvf openssl-1.0.1j.tar.gz$ cd openssl-1.0.1j$ ./config$ make && make install第四步:安装zlib库存$ cd /usr/local/$ wget /zlib-1.2.11.tar.gz$ tar -zxvf zlib-1.2.11.tar.gz$ ./configure$ make && make install第五步:安装nginx$ cd /usr/local/$ wget /download/nginx-1.8.0.tar.gz$ tar -zxvf nginx-1.8.0.tar.gz$ cd nginx-1.8.0$ ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module (注: --with-http_ssl_module:这个不加后⾯在nginx.conf配置ssl:on后,启动会报nginx: [emerg] unknown directive "ssl" in /opt/nginx/conf/nginx.conf 异常)$ make && make install启动nginx$ /usr/local/nginx/sbin/nginx第六步:检查是否启动成功打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表⽰ Nginx 已经安装并运⾏成功.记录我这个过程中遇见的事情:进⾏到第六步时,与浏览器的连接是不成功的,出现⽆响应,所以我去检查了防⽕墙的80端⼝是否有开通.命令为:firewall-cmd --list-all 检查80端⼝firewall-cmd --zone=public --add-port=80/tcp 若80端⼝没有开启,则打开80端⼝firewall-cmd --reload 重新打开防⽕墙再次重新开启nginx服务:/usr/local/nginx/sbin/nginx –s reload发现还是⽆法连接到此IP地址,检查本地连接是否正常:命令为:curl localhost显⽰如图⽚,发现本地连接是成功的,但是ip就是⽆法访问最后查了查发现,是因为新的服务器,阿⾥云安全组只开放了22和3389端⼝导致的,但是并未开放80端⼝。

CentOS系统rpm安装Nginx和配置

CentOS系统rpm安装Nginx和配置

CentOS系统rpm安装Nginx和配置⽬录CentOS rpm安装Nginx和配置介绍rpm包安装启动服务配置CentOS rpm安装Nginx和配置介绍Nginx(“engine x”)是⼀款由俄罗斯的程序设计师Igor Sysoev所开发⾼性能的 Web和反向代理服务器,也是⼀个IMAP/POP3/SMTP 代理服务器。

rpm包安装#安装nginx,rpm安装#rpm安装nginx包rpm -Uvh --force --nodeps nginx-1.16.1-1.el7.ngx.x86_64.rpm#查看启动状态systemctl status nginx显⽰如下:● nginx.service - nginx - high performance web serverLoaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)Active: active (running) since 五 2021-11-26 11:12:41 CST; 5 days agoDocs: /en/docs/Process: 1379 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)Main PID: 1543 (nginx)Tasks: 5CGroup: /system.slice/nginx.service├─1543 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf├─1544 nginx: worker process├─1546 nginx: worker process├─1547 nginx: worker process└─1548 nginx: worker process11⽉ 26 11:12:41 liang systemd[1]: Starting nginx - high performance web server...11⽉ 26 11:12:41 liang systemd[1]: Started nginx - high performance web server.#启动systemctl start nginx#重启systemctl restart nginx#开机⾃启动服务systemctl enable nginx#查看开机启动状态 enabled:开启, disabled:关闭systemctl is-enabled nginx安装完后在修改 /etc/nginx/conf.d/default.conf 配置⽂件,参考内容如下:vim /etc/nginx/conf.d/default.confserver {listen 80;server_name localhost;#charset koi8-r;#access_log /var/log/nginx/host.access.log main;location /ui {alias /data/dist;index index.html index.htm;}location /file/ {root /home/data/;index index.html index.htm;}# websocket配置wsslocation /liangws/ {proxy_pass http://192.168.0.19:8080/;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";proxy_set_header Remote_addr $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_read_timeout 600s;}location ~ /gat {proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://localhost:18080 ;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root /usr/share/nginx/html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}注意:静态⽂件下载,需要依赖nginx,我们需要将这些⽂件放到 nginx配置⽂件中的 /home/data/aaa 对应的⽬录下。

CentOS8下nginx服务器安装及配置笔记

CentOS8下nginx服务器安装及配置笔记

CentOS8下nginx服务器安装及配置笔记参考⽂档参考⽂档安装在CentOS下,nginx官⽅提供了安装包可以安装⾸先先安装前置软件sudo yum install yum-utils然后将nginx官⽅源加⼊到yum源中#/etc/yum.repos.d/nginx.repo[nginx-stable]name=nginx stable repobaseurl=/packages/centos/$releasever/$basearch/gpgcheck=1enabled=1gpgkey=https:///keys/nginx_signing.keymodule_hotfixes=true[nginx-mainline]name=nginx mainline repobaseurl=/packages/mainline/centos/$releasever/$basearch/gpgcheck=1enabled=0gpgkey=https:///keys/nginx_signing.keymodule_hotfixes=truenginx分为稳定和主线分⽀两个分⽀,默认为稳定分⽀,可以根据需要切换为主线分⽀sudo yum-config-manager --enable nginx-mainline使⽤命令就可以安装nginx了sudo yum install nginxnginx运⾏管理执⾏nginx命令可以开启服务器。

-?参数可以获取更多命令⾏参数nginx -s stop|quit|reload|reopen可以控制服务器直接退出|结束⼯作并退出|重新加载配置⽂件(重启)|重新打开⽇志⽂件ps axw -o pid,ppid,user,%cpu,vsz,wchan,command | egrep '(nginx|PID)'可以列出nginx的主进程pid和⼯作进程pid。

NginxWebUI--强大的nginx可视化配置工具

NginxWebUI--强大的nginx可视化配置工具

NginxWebUI--强大的nginx可视化配置工具前言本文介绍一下NginxWebUI,通过这款工具我们可以轻松的以图形化方式来配置我们的Nginx的各项功能,包括HTTP协议转发,TCP协议转发,反向代理,负载均衡,SSL证书自动申请、续期。

NginxWebUI可以部署在Ubuntu、CentOS、Windows等各个平台,可以通过本地部署或者通过Docker镜像来部署,其中Docker部署是最为简单的,只需要拉取镜像、创建并启动容器,接下来将演示如何使用Docker来部署NginxWebUI。

官网环境系统:CentOS 7 Docker:20.10.11拉取镜像docker pull cym1102/nginxwebui:latest在这里插入图片描述创建并启动容器大家可以根据自己的习惯来自定义nginxWebUI容器与宿主机的映射目录这段创建容器命令使用了--net=host,直接映射本机端口, 因为内部nginx可能使用任意一个端口, 所以必须映射本机所有端口.docker run -d -v /mydata/nginxWebUI:/home/nginxWebUI -e BOOT_OPTIONS="--s erver.port=8080" --privileged=true --net=host cym1102/nginxwebui:latest但是本人一般只用得到80端口和443端口,而nginxWebUI也要用到8080端口,这里我以端口映射的方式来监听:-p 80:80 -p 443:443 -p 8080:8080自定义端口映射就会有局限性,在配置中你如果代理到其它端口就无法监听到了,所以如果你想端口随意监听请用上面那条命令,如果和我一样只用得到80和443那就请用下面这条命令docker run -itd -v /mydata/nginxWebUI:/home/nginxWebUI -e BOOT_OPTIONS="--server.port=8080" --privileged=true -p 80:80 -p 443:443 -p 8080:8080 cym1102/ng inxwebui:latest /bin/bashimage注意:•容器需要映射路径/mydata/nginxWebUI:/home/nginxWebUI, 此路径下存放项目所有数据文件, 包括数据库, nginx配置文件, 日志, 证书等, 升级镜像时,此目录可保证项目数据不丢失. 请注意备份.•-e BOOT_OPTIONS 参数可填充java启动参数, 可以靠此项参数修改端口号, "--server.port 占用端口", 不填默认以8080端口启动•日志默认存放在/mydata/nginxWebUI/log/nginxWebUI.log查看容器docker psimage容器正常启动image访问后台管理由于创建容器的时候我的容器端口参数--server.port=8080设置的为8080,所以我们就要使用服务器IP+8080端口就可以访问到后台。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

安装Nginx 和相关的插件
(Image Filter Module & Upload Module & Upload Progress Module) (1) install essential sys library
$ yum -y install gcc-c++
$ yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel gd gd-devel
(2)install nginx & related module plugin
$ wget https:///masterzen/nginx-upload-progress-module/archive/v0.9.1.tar.gz
$ wget https:///vkholodkov/nginx-upload-module/archive/2.2.0.tar.gz
$ wget /download/nginx-1.3.8.tar.gz
$ tar zxvf *.tar.gz
$ cd /nginx-1.3.8/conf
(3)configure nginx.conf
$ vi nginx.conf
#user root;
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;
client_max_body_size 30M;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream backend{
ip_hash;
server 127.0.0.1:8080;
keepalive 32;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location = / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location ^~ /static/ {
root /usr/share/nginx/html;
}
location ^~ /images/ {
root /usr/share/nginx/uploads/;
}
location ~* ^/resize/([\d\-]+)/([\d\-]+)/(.+)$ { alias /usr/share/nginx/uploads/images/$3;
image_filter resize $1 $2;
image_filter_buffer 8M;
}
location /upload {
upload_pass /mobile/upload;
upload_store /usr/share/nginx/uploads/images 1;
upload_store_access user:rw;
upload_set_form_field "${upload_field_name}.fieldName" $upload_field_name;
upload_set_form_field "${upload_field_name}.name" $upload_file_name;
upload_set_form_field "${upload_field_name}.contentType" $upload_content_type;
upload_set_form_field "${upload_field_name}.path" $upload_tmp_path;
upload_aggregate_form_field "${upload_field_name}.md5" $upload_file_md5;
upload_aggregate_form_field "${upload_field_name}.size" $upload_file_size;
# upload_pass_form_field "^.*$";
upload_limit_rate 0;
upload_cleanup 400 404 499 500-505;
upload_pass_args on;
}
location / {
proxy_pass http://backend;
proxy_intercept_errors on;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#error_page 404 /404.html
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
(4)nginx add module
$ ./configure --add-module=../nginx-upload-module-2.2.0/ --add-module=../nginx-upload-progress-module-0.9.1/ --prefix=/usr/local/nginx
--with-http_ssl_module --with-http_image_filter_module
$ make
$ make install
$/usr/local/nginx/sbin/nginx (启动)
$/usr/local/nginx/sbin/nginx -s stop(停止)
PS:
upload_pass /mobile/upload;(tomcat后端项目处理上传信息的路径)
upload_store /usr/share/nginx/uploads/images 1;(上传图片的存储路径)
#配置拦截请求到tomcat
location / {
proxy_pass http://backend;
proxy_intercept_errors on;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
upstream backend{
ip_hash;
server 127.0.0.1:8080;
keepalive 32;
}。

相关文档
最新文档