skip to Main Content

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?

2

Answers


  1. 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;
        }
    }
    
    Login or Signup to reply.
  2. 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" />
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search