nginx 配置代理 配置图片

 

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

sendfile on;

keepalive_timeout 65;

 

#gzip on;

 

server {

listen 80;

server_name localhost;

 

 

root D:/recruit1.4;

index index.html index.htm;

#访问后缀代理配置

location /xtimg/ {

proxy_pass http://127.0.0.1:8010/;

}

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

}

}

server {#图片访问配置

listen 8010;

server_name localhost;

 

#charset koi8-r;

 

#access_log logs/host.access.log main;

 

location / {

alias d:/xzcimg/;

autoindex on;

}

 

location /upload/ {

alias d:/xzcimg/;

autoindex on;

}

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

#}

location ~ .*\.(gif|jpg|jpeg|png)$ {

expires 24h;

root d:/xzcimg/;#指定图片存放路径

proxy_temp_path d:/xzcimg/;#图片访问路径

 

}

}

 

# 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是一款流行的开源Web服务器,也可以作为反向代理和负载均衡器使用。如果你想让Nginx作为本地图片服务器,可以按照以下步骤配置: 1. **安装Nginx**: 如果你的系统上还没有安装Nginx,首先需要下载并安装它。对于Linux,你可以使用包管理器(如apt-get或yum)来安装;对于Windows,可以从官方网站下载适用于Windows的二进制版本。 2. **创建站点目录**: 创建一个用于存储图片的文件夹,比如`/var/www/images` 或者 `D:\nginx\images`,并将图片上传到这个目录。 3. **编辑Nginx配置**: 打开Nginx配置文件,通常位于`/etc/nginx/nginx.conf` (Linux) 或 `C:\nginx\conf\nginx.conf` (Windows),用文本编辑器打开它。 4. **添加location块**: 配置一个location块来指定处理静态文件,包括图片。例如: ```nginx location ~ \.(gif|jpg|jpeg|png)$ { root /path/to/images; # 使用实际路径替换这里的路径 access_log off; expires max; # 设置图片默认缓存时间 } ``` 这里`~ \.(gif|jpg|jpeg|png)$` 匹配`.gif`, `.jpg`, `.jpeg`, 和 `.png` 类型的文件,并设置它们的访问路径。 5. **启用服务器和重启Nginx**: 将上述配置添加到配置文件后,保存并关闭文件。然后使用命令行重启Nginx服务,例如: - Linux: `sudo service nginx restart` - Windows: `nginx.exe -s reload` 现在,你的Nginx服务器已经可以作为本地图片服务器了。外部请求图片时,只要URL指向正确的路径,Nginx会自动返回对应的图片
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值