html5移动web开发,HTML列表标签

一、nginx简介

Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型的网页服务器中表现较好。

Nginx专门为性能优化而开发,性能是其最重要的考量,实际上非常注重效率,能经起高负载的考验,有报告表明能支持高达50000个并发连接数。

二、反向代理

1.正向代理

在客户端(浏览器)配置代理服务器,通过代理服务器进行互联网访问。

2.反向代理

我们只需要将请求发送到反向代理服务器,由反向代理服务器去选择目标服务器获取数据后,再返回给客户端,此时反向代理服务器和目标服务器对外就是一个服务器,暴露的是代理服务器地址,隐藏了真实服务器IP地址。

三、负载均衡

增加服务器的数量,然后将请求分发到各个服务器上,将原先请求集中到单个服务器上的情况改为分发到多个服务器上,将负载分发到不同的服务器,也就是我们所说的负载均衡。

四、动静分离

为了加快网站的解析速度,可以把动态页面和静态页面由不同的服务器来解析,加快解析速度。减低原来单个服务器的压力。

五、nginx常用命令

1.使用nginx操作命令前提条件:必须进行nginx的目录

2.查看nginx的版本号

nginx -v

3.启动nginx

nginx

4.关闭nginx

nginx -s stop

5.重新加载nginx

nginx -s reload

六、nginx的配置文件(nginx.conf)

nginx配置文件有三部分组成

1.全局块

从配置文件开始到events块之间的内容,主要会设置一些影响nginx服务器整体运行的配置指令。

比如:worker_processes 1; worker_processes值越大,可以支持的并发处理量也越多。

2.events块

events块涉及的指令主要影响nginx服务器与用户的网络连接。 
比如:worker_connection 1024; 支持的最大连接数。

3.http块

nginx服务器配置中最频繁的部分,http块也可以包括http全局块、server块。

七、nginx配置图片的访问路径

图片文件上传至服务器D:/images中,然后通过IP地址/upload/加图片名称进行访问。

#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;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        #访问路径拼接 upload 访问本地绝对路径下的某图片 
        location /upload/ {
        alias D:/images/;
        autoindex on;
        }

        location / {
            root   html;
            index  index.html index.htm;
        }

        #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;
        }

        # 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;
        #}
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

配置好nginx.conf记得重启一下服务器。效果如图:

八、java后台代码

/**
 * 文件上传
 */
@RestController
public class FileController {

    @PostMapping(value = "/fileUpload")
    public String fileUpload(@RequestParam(value = "file") MultipartFile file) {
        if (file.isEmpty()) {
            System.out.println("请选择图片");
        }
        String fileName = file.getOriginalFilename();  // 文件名
        String suffixName = fileName.substring(fileName.lastIndexOf("."));  // 后缀名
        String filePath = "D:/images/"; // 上传后的路径
        fileName = UUID.randomUUID() + suffixName; // 新文件名
        File dest = new File(filePath + fileName);
        if (!dest.getParentFile().exists()) {
            dest.getParentFile().mkdirs();
        }
        try {
            file.transferTo(dest);
        } catch (IOException e) {
            e.printStackTrace();
        }
        //返回图片名称
        return fileName;
    }
}

这里将图片上传至D:/images文件夹中,因为前面配置了nginx的缘故,我这里是在本地测试的,直接使用localhost/upload/+返回的图片名称就可以访问到了。

如果想要通过项目的地址外加端口号进行访问的话,可以配置一个资源映射路径。

/**
 * 资源映射路径
 */
@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/upload/**").addResourceLocations("file:D:/images/");
    }
}

like this!

最后

篇幅有限,文章中的前端初阶笔记,学习路线图,和前端面试题都可以点击这里免费领取完整版PDF(含答案解析)。

《2021年前端面试题精选大全》内容大纲包括HTML,CSS,JavaScript,jQuery,浏览器,HTTP,React,小程序

【2021年前端面试题精选大全】

D-1627007626072)]

最后

篇幅有限,文章中的前端初阶笔记,学习路线图,和前端面试题都可以点击这里免费领取完整版PDF(含答案解析)。

《2021年前端面试题精选大全》内容大纲包括HTML,CSS,JavaScript,jQuery,浏览器,HTTP,React,小程序

[外链图片转存中…(img-NKwqH7nR-1627007626074)]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值