本文试验环境在Ubuntu16.04下
1.首先在终端输入
sudo apt-get install nginx
2.安装完成后测试,输入下面的命令,或者打开浏览器输入http://localhost
curl localhost
显示欢迎界面表示安装成功
3.在/home/lemon/Documents下新建一个images文件夹,并随便下载几张图片,命名为1.jpg,2.jpg...
4.进入/etc/nginx/site-enabled/目录下,将default文件进行备份,然后输入下面的命令
sudo vim default
修改为下面的内容
server { listen 80 ; server_name localhost; charset utf-8; location ~ .*\.(gif|jpg|jpeg|png)$ { expires 24h; root /home/lemon/Documents/images;#指定图片存放路径 proxy_store on; proxy_store_access user:rw group:rw all:rw; proxy_temp_path /home/lemon/Documents/images;#图片访问路径 proxy_redirect off; proxy_set_header Host 127.0.0.1; 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; if ( !-e $request_filename) { proxy_pass http://127.0.0.1;#默认80端口 } } root /var/www/html; # Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html; server_name _; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } }
5.输入下面的命令检验脚本中代码是否正确
sudo nginx -t
出现success则表示成功
6.输入下面的指令重新载入
sudo nginx -s reload
7.在浏览器中输入localhost/1.jpg则可以看到图片
原文地址:https://www.cnblogs.com/SakerLiu/p/9818167.html
时间: 2024-10-23 13:05:02