静态文件的nginx配置

发布于 2025-02-05 16:13:08 字数 325 浏览 2 评论 0原文

我需要一个建议,如何解决这个问题:

我有两个网站example1.com和example2.com 他们都在nuxtjs上做得很好。

对于他们来说,我正在使用nginx。

我需要这样做: 如果我打算地址example2.com/custompage,我需要从example1.com/custompage 中显示页面和静态文件(我不需要在此页面上重定向,我需要在example2.com/custompage上准确显示此页面),但是当我转到示例2.com的任何其他页面时,我需要将所有页面和文件保留在example2.com中

是否可以使用nginx执行此操作?

I need an advice, how to solve this:

I have two websites example1.com and example2.com
They both made on NuxtJS and works well.

For them I am using Nginx.

I need to do this:
If I going to address example2.com/custompage I need to show page and static files from example1.com/custompage (I am not need redirect on this page, I need to show this page exactly on example2.com/custompage), but when I going to any other page of example2.com I need to keep all pages and files from example2.com

Is it possible to do this with Nginx?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久伴你 2025-02-12 16:13:08

您可以使用proxy_pass。首先,在两个端口中运行NUXTJS应用程序,例如30003001,然后使用代理通行证和上游

upstream nuxt1 {
    server localhost:3000;
}

upstream nuxt2 {
    server localhost:3001;
}

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

    server_name example2.com

    location /custompage/ {
        proxy_pass http://nuxt1/custompage/;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }

    location / {
        proxy_pass http://nuxt2;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }
}

You can use proxy_pass. First, run NuxtJS apps in two ports like 3000 and 3001 then use proxy pass and upstream to do that

upstream nuxt1 {
    server localhost:3000;
}

upstream nuxt2 {
    server localhost:3001;
}

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

    server_name example2.com

    location /custompage/ {
        proxy_pass http://nuxt1/custompage/;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }

    location / {
        proxy_pass http://nuxt2;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
    }
}
相思碎 2025-02-12 16:13:08

遵循上述步骤之后。

在NUXT项目(NUXT1)中,您需要将以下内容添加到NUXT.CONFIG.JS文件中,

router : {
  base: "/custompage/"
}

还请注意,如果您使用的是static文件夹中的任何文件,则示例图像,示例,示例。 PNG。

您必须使用它们,例如

<v-img src="example.png" />

而不是

<v-img src="/example.png" />

如果您使用的是动态变量,请在.env中添加一个变量

<v-img :src="ENV_VAR + dynamic_variable" />

After following the steps mentioned above.

In your Nuxt Project(nuxt1), you need to add the following to your nuxt.config.js file,

router : {
  base: "/custompage/"
}

Also, note if you are using any files from the Static folder, example an image , example.png.

You have to use them like

<v-img src="example.png" />

And NOT,

<v-img src="/example.png" />

If you are using dynamic variable, add an variable in .env , for the router.base

<v-img :src="ENV_VAR + dynamic_variable" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文