1.安装nginx包
sudo apt update
sudo apt install nginx
2.安装完成后系统自动启动nginx
sudo systemctl status nginx
查看nginx服务的状态
3.开启防火墙上的HTTP服务端口80
sudo ufw allow ‘Nginx HTTP’
4.在浏览器输入 http://localhost 看到nginx的欢迎界面,代表成功
5.更改nginx的配置文件
cd /etc/nginx/
sudo gedit nginx.conf
更改nginx.conf配置文件,在http{}内添加如下内容,修改如下:
server{listen 8090;#80server_name localhost;
location ~ .*\.(gif|jpg|jpeg|png)$ { #expires 24h; root /home/wqh/savingImages/20230816/;#指定图片存放路径 autoindex on;#access_log /njbestway/server/logs/images.log;#日志存放路径 proxy_store on; proxy_store_access user:rw group:rw all:rw; proxy_temp_path /home/wqh/savingImages/20230816/;#图片访问路径 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; proxy_temp_file_write_size 640k; if ( !-e $request_filename) { proxy_pass http://127.0.0.1;#默认80端口 } } }
保存后重新启动nginx服务
systemctl restart nginx.service
结果
在Ubantu中目录下/home/wqh/savingImages/20230816/存在下面图片
在浏览器打开url:http://192.168.182.138:8090/2023-08-16-17-05-00-650.jpg 即可看到图片