hirenPublic怎么用nginx规则去掉public这个尾巴
在nginx的配置文件中,可以使用rewrite规则将URL中的public尾部删除。具体方法如下:
-
打开nginx的配置文件,一般位于/etc/nginx/nginx.conf或/usr/local/nginx/conf/nginx.conf
-
在server段中添加以下代码:
location /public {
rewrite ^/public(.*)$ $1 last;
}
- 保存配置文件并重新启动nginx服务。重启命令为:sudo service nginx restart
以上代码的意思是,将所有以/public开头的URL重写为去掉/public的URL。例如,/public/test.html将被重写为/test.html。这样,访问时就不需要输入/public这个尾巴了。
原文地址: https://www.cveoy.top/t/topic/e3yK 著作权归作者所有。请勿转载和采集!