主机sveltekit适配器节点生成的构建版本,其中nginx proxy_pass位于/以外的路径上

am46iovg  于 2023-03-17  发布在  Nginx
关注(0)|答案(1)|浏览(160)

我想通过地址为mydomain.com/dashboard_v2nginxproxy_pass提供从adaptor-node生成的sveltekit构建版本
svelte.config.js

import adapter from '@sveltejs/adapter-node';
import preprocess from "svelte-preprocess";

/** @type {import('@sveltejs/kit').Config} */
const config = {
    kit: {
        adapter: adapter(),
        csrf: { checkOrigin: false },
        paths: {base: '/dashboard_v2'}
    },
};

export default config;

我正在使用npm run build进行构建
我正在使用npm run preview -- --host运行
/etc/nginx/sites-enabled/mydomain.com

server {
       listen 80;
       listen [::]:80;

       server_name mydomain.com;

       root /home/ubuntu/website;
       index index.html;

       location / {
               try_files $uri $uri/ =404;
       }

        location /dashboard_v2/ {
                proxy_pass http://localhost:4173/dashboard_v2;
                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                # WebSocket support
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
        }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/test.trimpixel.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/test.trimpixel.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

此配置产生too many redirect错误。
此版本在location /下运行良好,但在location /dashboard_v2下无法运行
要使location /dashboard_v2工作,需要做哪些更改?

ojsjcaue

ojsjcaue1#

你好,我所知道的https的代码,需要在一个单独的服务器块。

server {
    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/test.trimpixel.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/test.trimpixel.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

然后从侦听端口80的服务器重定向到443
您可以查看this repo以获得完整的示例

相关问题