美文网首页
nginx 伪静态配置

nginx 伪静态配置

作者: 国服最坑开发 | 来源:发表于2023-07-02 18:53 被阅读0次
  • 需求

/mypath/ 下面所有的请求,都返回 index.html 这个静态资源。
应用场景:单页面web应用,内部支持多路由进行页面渲染。

  • 关键配置
        location /mypath/ {
                 add_header Access-Control-Allow-Origin *;
                 add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
                 add_header Access-Control-Allow-Headers *;
                 add_header Cache-Control no-cache;
                 if ($request_method = 'OPTIONS') {
                        return 204;
                 }

                default_type text/html;

                # 实际会去目录  /app/nginx/static/mypath/ 下面找东西
                root /app/nginx/static;
                index index.html index.htm;
                try_files $uri $uri/ @guiderewrite;
        }

        location @guiderewrite {
                rewrite ^(.+)$  /mypath/index.html last;
        }

相关文章

网友评论

      本文标题:nginx 伪静态配置

      本文链接:https://www.haomeiwen.com/subject/sywfudtx.html