nginx配置访问本地资源
参考博客:https://www.cnblogs.com/xy51/p/9973326.html
需要访问路径:http://IP:10013/p1upgrade/picfiles/image73b456273df34da58db8f36166bb49e1
获取nginx配置位置,查看nginx的状态,就会显示加载配置文件路径,添加如下,然后重启nginx即可:
server { listen 10013; location /p1upgrade/ { root /; rewrite ^/p1upgrade/(.*)$ /home/tomcat/p1upgrade-tomcat-7.0.53/webapps/p1upgrade/$1 break; } }
采用这种方式,可以添加虚拟目录,如下示例
有一个文件/usr/share/nginx/html/index01.html
访问地址为http://localhost/x/index01.html
配置如下
user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { 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 /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 4096; include /etc/nginx/mime.types; default_type application/octet-stream; include /etc/nginx/conf.d/*.conf; server { listen 80; listen [::]:80; server_name _; root /usr/share/nginx/html; error_page 404 /404.html; location = /404.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } location /x/ { root /; # 这一行必须加上,我测试结果是不加就不能正常访问到对应的页面 rewrite ^/x/(.*)$ /usr/share/nginx/html/$1 break; } } }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步