在大部分情况下,nginx在linux进行使用。

  但是在工作场景下,还是存在的。图片都在库里,这种对于sql来说,就是一个灾难。

1.方案

  我们将图片搞出来,放在硬盘上,然后将路径放到sql里。

  图片的访问,通过nginx。

 

2.说明

  这篇文档,记录下windows下,访问图片的配置。

  其他的访问不变

 

3.下载nginx
   http://nginx.org/download/nginx-1.17.10.zip
   注1:此版本为window版本

 

4.安装

  简单的解压即可

  

 

 

 

 

5.启动

  打开cmd容器,切换到nginx安装根目录

  start nginx.exe         //启动nginx

  

  访问:

  http://localhost:80

  

 

 

  PS:其他命令:

nginx.exe -s stop      //快速停止nginx
nginx.exe -s reload    //重新加载nginx
nginx.exe -s quit      //完整停止nginx

 

6.配置conf

  在server下添加对图片的代理

server {
        listen       8086;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
        
        location ~*.*.(gif|jpg|jpeg|png|bmp|swf)$ {
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Headers X-Requested-With;
            add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
            root E:\data1\picTest;#指定图片存放路径  
        }


.........

 

  完整的配置:

#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       8086;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
        
        localtion ~*.*.(gif|jpg|jpeg|png|bmp|swf)$ {
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Headers X-Requested-With;
            add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS;
            root E:\data1\picTest;#指定图片存放路径   
        }

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

}

 

  其中,图片位置:

  

 

 

 

 

 

 7.访问效果

  启动

  

 

 

 

  

8.其他配置

  在这里会思考,其他的配置是否会被影响

  其实,这里在访问的时候,不走nginx的端口,就不会影响到。

 

  可以理解为,这个是其中的一个机器,只提供图片的访问,如上文的8086端口。正常的jar继续走8090端口,互不影响。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

 posted on 2022-06-29 20:21  曹军  阅读(134)  评论(0编辑  收藏  举报