简体   繁体   中英

nginx how can I rewrite a location

I want http://localhost/health -> http://localhost/health.html , how can I write my location config?

this is my location ,but It does not work.

location ^~  /health {
    root   /usr/share/nginx/html;
    index  health.html ;
}

location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
}

Thanks for your help.

Use the rewrite directive.

location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;

    rewrite ^/heath/?$ /health.html? break;
}

Source: http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM