时间:2023-07-14 12:27:01 | 来源:网站运营
时间:2023-07-14 12:27:01 来源:网站运营
VSFTPD Nginx:VSFTPD<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.sxt</groupId> <artifactId>parent</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <!-- 对依赖的jar包的版本统一进行定义 --> <properties> <junit.version>4.12</junit.version> <spring.version>4.1.3.RELEASE</spring.version> <mybatis.version>3.2.8</mybatis.version> <mybatis.spring.version>1.2.2</mybatis.spring.version> <mysql.version>5.1.32</mysql.version> <slf4j.version>1.6.4</slf4j.version> <druid.version>1.0.9</druid.version> <jstl.version>1.2</jstl.version> <servlet-api.version>2.5</servlet-api.version> <tomcat.version>2.2</tomcat.version> <jsp-api.version>2.0</jsp-api.version> <zkClient-version>0.10</zkClient-version> <dubbo-version>2.5.4</dubbo-version> <jackson.version>2.4.2</jackson.version> <commons-net.version>3.3</commons-net.version> <commons-fileupload.version>1.3.1</commons-fileupload.version> </properties> <!-- jar包的依赖注入 ,由于该工程是一个父工程,所以jar包在该pom文件中只是声明 --> <dependencyManagement> <dependencies> <!-- 单元测试 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> </dependency> <!-- 日志处理 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> <!-- Mybatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>${mybatis.spring.version}</version> </dependency> <!-- MySql --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.version}</version> </dependency> <!-- 连接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>${druid.version}</version> </dependency> <!-- Spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>${spring.version}</version> </dependency> <!-- JSP相关 --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>${jstl.version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>${servlet-api.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>${jsp-api.version}</version> <scope>provided</scope> </dependency> <!-- 文件上传组件 --> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>${commons-fileupload.version}</version> </dependency> <dependency> <groupId>commons-net</groupId> <artifactId>commons-net</artifactId> <version>${commons-net.version}</version> </dependency> <!-- Jackson Json处理工具包 --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackson.version}</version> </dependency> </dependencies> </dependencyManagement> <build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.xml</include> <include>**/*.properties</include> </includes> </resource> </resources> <!-- tomcat插件,由于子项目不一定每个都是web项目,所以该插件只是声明,并未开启 --> <pluginManagement> <plugins> <!-- 配置Tomcat插件 --> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>${tomcat.version}</version> </plugin> </plugins> </pluginManagement> </build></project>
创建 kindEditorDemo <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.sxt</groupId> <artifactId>parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <groupId>com.sxt</groupId> <artifactId>kindEditorDemo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <dependencies> <!-- 单元测试 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> <!-- 日志处理 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <!-- JSP相关 --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <scope>provided</scope> </dependency> <!-- 文件上传组件 --> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> </dependency> <dependency> <groupId>commons-net</groupId> <artifactId>commons-net</artifactId> </dependency> <!-- Jackson Json处理工具包 --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency> </dependencies> <build> <plugins> <!-- 配置Tomcat插件 --> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <configuration> <path>/</path> <port>8080</port> </configuration> </plugin> </plugins> </build></project>
框架整合 FTP_HOST=192.168.219.128FTP_PORT=21FTP_USERNAME=ftpuserFTP_PASSWORD=1234FTP_BASEPATH=/home/ftpuser/HTTP_BASE_PATH=http://img.bjsxt.com
KindEditor 使用方式 package com.sxt.web.controller;import java.util.Map;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;import org.springframework.web.multipart.MultipartFile;import com.sxt.commons.JsonUtils;import com.sxt.service.PicUploadService;@Controller@RequestMapping("/pic")public class PicUploadController { @Autowired PicUploadService picUploadService; @RequestMapping("/upload") @ResponseBody public String fileUpload(MultipartFile fileName){ Map<String, Object> map = picUploadService.fileUpload(fileName); return JsonUtils.objectToJson(map); }}
PicUploadService package com.sxt.service;import java.util.Map;import org.springframework.web.multipart.MultipartFile;public interface PicUploadService { Map<String ,Object> fileUpload(MultipartFile filename);}
PicUploadServiceImpl package com.sxt.service.impl;import java.io.IOException;import java.text.SimpleDateFormat;import java.util.Date;import java.util.HashMap;import java.util.Map;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Service;import org.springframework.web.multipart.MultipartFile;import com.sxt.commons.FtpUtil;import com.sxt.commons.IDUtils;import com.sxt.service.PicUploadService;@Servicepublic class PicUploadServiceImpl implements PicUploadService { @Value("${FTP_HOST}") private String FTP_HOST; @Value("${FTP_PORT}") private int FTP_PORT; @Value("${FTP_USERNAME}") private String FTP_USERNAME; @Value("${FTP_PASSWORD}") private String FTP_PASSWORD; @Value("${FTP_BASEPATH}") private String FTP_BASEPATH; @Value("${HTTP_BASE_PATH}") private String HTTP_BASE_PATH; @Override public Map<String, Object> fileUpload(MultipartFile filename) { Map<String, Object> map = new HashMap<String, Object>(); Date date = new Date(); try { SimpleDateFormat sdf = new SimpleDateFormat("/yyyy/MM/dd/"); String path = sdf.format(date); String newFileName = IDUtils.genImageName()+filename.getOriginalFilename().substring(filename.getOriginalFilename().lastIndexOf(".")); boolean flag = FtpUtil.uploadFile(this.FTP_HOST, this.FTP_PORT, this.FTP_USERNAME, this.FTP_PASSWORD, this.FTP_BASEPATH, path, newFileName, filename.getInputStream()); if (flag) { map.put("error", 0); map.put("url", this.HTTP_BASE_PATH+path+newFileName); } else { map.put("error", 1); map.put("msg", "上传失败!"); } } catch (IOException e) { map.put("error", 1); map.put("msg", "上传失败!"); e.printStackTrace(); } return map; }}
提交 KindEditor 中的数据 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title><script type="text/javascript" src="js/kindeditor/kindeditor.js"></script><script type="text/javascript" src="ja/kindeditor/lang/zh_CN.js"></script><script type="text/javascript" src="js/jquery-1.7.2.js"></script> <script type="text/javascript"> $(function(){ var obj; KindEditor.ready(function(K) { obj = K.create('#test_id', { uploadJson : '/pic/upload', filePostName: 'fileName', dir: "image" }); }); $("#but").click(function(){ obj.sync(); $.post("/content/save",$("#myForm").serialize(),function(data){ if(data.status == 200){ alert("提交成功!"); }else{ alert("提交失败!"); } }); }); }); </script></head><body> <form action="" id="myForm"> <textarea rows="20" cols="70" id="test_id" name="desc"></textarea> <input type="button" value="ok" id="but"/> </form></body></html>
IPADDR=192.168.10.144 NETMASK=255.255.255.0 GATEWAY=192.168.10.2 DNS1=114.114.114.114
IP 绑定 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; sendfile on; #tcp_nopush on;#keepalive_timeout 0; keepalive_timeout 65; #gzip on; #一个 Server 就是一个虚拟主机 server { listen 80;#为虚拟机指定 IP 或者是域名 server_name 192.168.70.144;#主要配置路由访问信息location / { #用于指定访问根目录时,访问虚拟主机的 web 目录 root html144; #在不指定访问具体资源时,默认的展示资源的列表 index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }#一个 Server 就是一个虚拟主机 server { listen 80;#为虚拟机指定 IP 或者是域名 server_name 192.168.70.188;#主要配置路由访问信息 location / { #用于指定访问根目录时,访问虚拟主机的 web 目录 root html188; #在不指定访问具体资源时,默认的展示资源的列表 index index.html index.htm; }error_page 500 502 503 504 /50x.html;location = /50x.html { root html; } }}
基于端口的虚拟主机配置方式节点说明:在 http 节点里添加:#定义负载均衡设备的 Ip 及设备状态upstream myServer {server 127.0.0.1:9090 down;server 127.0.0.1:8080 weight=2;server 127.0.0.1:6060;server 127.0.0.1:7070 backup;}在需要使用负载的 Server 节点下添加proxy_pass http://myServer;upstream 每个设备的状态:down 表示单前的 server 暂时不参与负载weight 默认为 1.weight 越大,负载的权重就越大fail_timeout:次失败后,暂停的时间 默认 10smax_fails :允许请求失败的次数默认为 1.当超过最大次数时,返回backup: 其它所有的非 backup 机器 down 或者忙的时候,请求 backup 机器。所以这台机器压力会最轻。
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; sendfile on; keepalive_timeout 65;upstream tomcat_server1{server 192.168.70.143:8080 weight=10;server 192.168.70.143:9090 weight=2; } server { listen 80;#为虚拟机指定 IP 或者是域名 server_name test.bjsxt.com;#主要配置路由访问信息 location / { #用于指定访问根目录时,访问虚拟主机的 web 目录 proxy_pass http://tomcat_server1; #在不指定访问具体资源时,默认的展示资源的列表 index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }}}
http 协议代理 FTP_HOST=192.168.70.144FTP_PORT=21FTP_USERNAME=ftpuserFTP_PASSWORD=ftpuserFTP_BASEPATH=/home/ftpuser/HTTP_BASE_PATH=http://img.bjsxt.com
修改 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; sendfile on; keepalive_timeout 65; server { listen 80;#为虚拟机指定 IP 或者是域名 server_name img.bjsxt.com;#主要配置路由访问信息 location / { #用于指定访问根目录时,访问虚拟主机的 web 目录 root /home/ftpuser/; #在不指定访问具体资源时,默认的展示资源的列表 index index.html index.htm; }error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}
关键词: