【问题标题】:Partially using Vue with nginx部分使用 Vue 和 nginx
【发布时间】:2020-03-28 21:42:18
【问题描述】:

我正在尝试将 vue.js 和 Django 与 nginx 一起使用。问题是,它仍然将我的 /subscriptions/ url 重定向到 Django。删除“/”规则会使其工作。当 url 匹配“自定义”时,有没有办法“跳过”Django?

基本上,我想指定哪些链接将与 vue 一起使用,其余的将与 Django 一起使用。

location = /custom/ {
    root /home/django/project/frontend/dist;
    index /index.html;
}

location / {
    include proxy_params;
    proxy_pass http://unix:/home/django/project/project.sock;
}

【问题讨论】:

    标签: django vue.js nginx


    【解决方案1】:

    如果请求的路径以'/custom/'开头,则以下将提供/home/django/project/frontend/dist/中的文件

    location /custom/ {
        root /home/django/project/frontend/dist/;
        index /index.html;
    }
    
    location / {
        include proxy_params;
        proxy_pass http://unix:/home/django/project/project.sock;
    }
    

    【讨论】:

    • 不幸的是,这会返回 django 404 错误和“请求 URL:domain_com/index.html
    • 您尝试访问的确切 URL 是什么?
    • domain.com/custom/
    • 你能否用整个 nginx 配置、nginx access.log 的内容和 error.log 文件更新你的问题
    • 这只是默认的东西。日志显示没有错误,access.log 有一个 404 调用。删除 / 规则使 vue 工作。如果我要加一个回报500;到 /custom/ 它将返回 500 错误。但它不是,它只是将请求重定向到 Django。
    【解决方案2】:

    这是解决方案。出于某种原因,它需要在根中使用 2 个斜杠。

    root /home/django/tradeium/frontend/dist//;
    index index.html;
    
    location / {
        include proxy_params;
        proxy_pass http://unix:/home/django/project/project.sock;
    }
    
    location = /custom/ {
    
        try_files $uri $uri/ index.html;
    }
    

    【讨论】:

      猜你喜欢
      • 2020-02-01
      • 1970-01-01
      • 2016-06-05
      • 2020-05-07
      • 2019-11-27
      • 2021-06-05
      • 1970-01-01
      • 1970-01-01
      • 2022-08-16
      相关资源
      最近更新 更多