Nginx的conf文件位置和重写不起作用

我在nginx上运行magento
我的根是/pub
但有一些扩展试图链接到www.myurl.com/pub/xxx.file ,所以我想要将所有/pub改写为/

我的计划是www.myurl.com/pub/xxx.file成为www.myurl.com/xxx.file ,但它不起作用。

这里是我的conf文件( abcdefg是一个testing目录):

 server { listen 443 ssl http2; server_name www.myurl.com ; index index.html index.htm index.php default.html default.htm default.php; root /home/wwwroot/www.myurl.com/pub; ssl on; ssl_certificate /etc/letsencrypt/live/www.myurl.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/www.myurl.com/privkey.pem; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers "myciphers"; ssl_session_cache builtin:1000 shared:SSL:10m; ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem; location /pub { rewrite /pub /; } location ^~/abcdefg { rewrite /abcdefg/ /1234567/; } include other.conf; if (!-e $request_filename) { rewrite ^(.+)$ /index.php; } set $MAGE_MODE production; include enable-php.conf; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } #location ~ /.well-known { # allow all; #} #location ~ /\. #{ # deny all; #} access_log /home/wwwlogs/shopkey.doyustudio.com.log; error_log /home/wwwlogs/shopkey.doyustudio.com.error.log debug; } 

而不是设置root /home/wwwroot/www.myurl.com/pub; 使用root /home/wwwroot/www.myurl.com/; 然后在pub dir上创build一个位置,就像这样

 location / { try_files /pub/$uri $uri; } 

这就是说要先在pub目录下search$ uri,如果不存在的话试试在root目录下