使用Nginx搭建图片服务器(windows环境下)

 更新时间:2018年06月27日 11:38:06   作者:shuaiflying  
这篇文章主要介绍了使用Nginx搭建图片服务器(windows环境下),小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

知识点:在windows系统中,搭建图片上传服务器

1.进入官网下载nginx压缩包,解压后目录如下

2.在解压后的conf/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;

server {
listen 8089;
server_name localhost;

#charset utf-8;
#access_log logs/host.access.log main;

#添加博客的代码
location ~ .*\.(gif|jpg|jpeg|png)$ { 
expires 24h; 
root G:/images/;#指定图片存放路径 
access_log G:/images/log;#图片路径 
proxy_store on; 
proxy_store_access user:rw group:rw all:rw; 
proxy_temp_path G:/images/;#图片路径 
proxy_redirect off; 

proxy_set_header Host 127.0.0.1; 
proxy_set_header X-Real-IP $remote_addr; 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
client_max_body_size 10m; 
client_body_buffer_size 1280k; 
proxy_connect_timeout 900; 
proxy_send_timeout 900; 
proxy_read_timeout 900; 
proxy_buffer_size 40k; 
proxy_buffers 40 320k; 
proxy_busy_buffers_size 640k; 
proxy_temp_file_write_size 640k; 
if ( !-e $request_filename) 
{ 
proxy_pass http://169.254.140.133:8089; #代理访问地址
} 
} 

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

3.点击绿色的nginx.exe图标,启动服务器,在任务管理器看到如下,则启动成功

4.在浏览器中输入http://127.0.0.1:8089可以看到

5.在G:/images/下,放一个图片,在浏览器地址栏输入http://127.0.0.1:8089/img.jpg,就可以访问到服务器上的图片

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • 详解Nginx中的Rewrite的重定向配置与实践

    详解Nginx中的Rewrite的重定向配置与实践

    这篇文章主要介绍了详解Nginx中的Rewrite的重定向配置与实践,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-03-03
  • Nginx启动失败:端口80被占用问题的解决方案

    Nginx启动失败:端口80被占用问题的解决方案

    在Linux服务器上部署 Nginx 时,可能会遇到 Nginx 启动失败的情况,尤其是错误提示bind()to 0.0.0.0:80 failed,这种问题通常是由于端口80被其他进程占用导致的,本文将详细分析这一问题的原因,并提供多种解决方案,帮助你快速恢复Nginx的正常运行
    2025-02-02
  • 在Nginx中隐藏版本号的方法详解

    在Nginx中隐藏版本号的方法详解

    Nginx是一款高性能的Web服务器软件,它支持反向代理、负载均衡、缓存等功能,在使用 Nginx 的过程中,有时候我们需要隐藏 Nginx 的版本号,以增强服务器的安全性,所以接下来小编将给大家介绍如何在Nginx中隐藏版本号,需要的朋友可以参考下
    2023-11-11
  • nginx 配置location匹配规则实例讲解

    nginx 配置location匹配规则实例讲解

    在本篇文章里小编给大家整理的是关于nginx 配置location匹配规则实例讲解内容,需要的朋友们学习下。
    2020-03-03
  • Nginx+Tomcat负载均衡集群的实现示例

    Nginx+Tomcat负载均衡集群的实现示例

    本文主要介绍了Nginx + Tomcat负载均衡集群的实现示例,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-10-10
  • 在Nginx中拦截特定用户代理的教程

    在Nginx中拦截特定用户代理的教程

    这篇文章主要介绍了在Nginx中拦截特定用户代理的教程,并为这些被拦截的用户设置一个黑名单以方便管理,需要的朋友可以参考下
    2015-06-06
  • Nginx请求访问控制实现方案

    Nginx请求访问控制实现方案

    Nginx并不直接实现漏桶算法或令牌桶算法,但这些算法在控制网络流量和请求速率方面非常有用,这些算法通常在网络编程、API服务、负载均衡等领域中使用,以确保系统的稳定性和性能,这篇文章给大家介绍Nginx请求访问控制实现方案,感兴趣的朋友跟随小编一起看看吧
    2024-05-05
  • 使用ngxtop实时监控Nginx日志文件的示例代码

    使用ngxtop实时监控Nginx日志文件的示例代码

    在Nginx日志分析领域,ngxtop是一款强大的实时监控工具,它能够即时解析Nginx的访问日志文件,提供直观、可定制的实时统计信息,帮助管理员更好地了解服务器的运行状况和Web流量,本文给大家介绍使用ngxtop实时监控Nginx日志文件的示例代码,需要的朋友可以参考下
    2024-01-01
  • Nginx设置Access-Control-Allow-Origin多域名跨域实现

    Nginx设置Access-Control-Allow-Origin多域名跨域实现

    本文主要介绍了Nginx设置Access-Control-Allow-Origin多域名跨域实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2024-11-11
  • nginx中proxy_pass各种用法详解

    nginx中proxy_pass各种用法详解

    nginx中配置location代理转发规则的时候不同写法对应不同转发规则。本文就介绍几种常见的匹配情况,感兴趣的可以了解一下
    2021-11-11

最新评论