navigating to the assets directory using nginx and vite

My setup involves using nginx and vite to docker vue.js, but I'm facing an issue when setting the base path where the browser screen goes blank. The /test/index HTML page loads fine, but the /test/assets/something.js and CSS files return as HTML. How can I modify my vite + base + nginx configuration to ensure that the following URLs are displayed correctly?

URL: htttp://localhost:808/test/index

vite.confign.ts

base: '/test/',

default.conf

server {
    listen   8080 default_server;
    server_name  "";

    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log main;

    location ~ ^/assets/(.*)$ {
        proxy_set_header X-Forwarded-For $remote_addr;
        root /home/vue_server/assets/$1;
        try_files $uri $uri/ /index.html;
    }

    location / {
        proxy_set_header X-Forwarded-For $remote_addr;
        root /home/vue_server/;
        try_files $uri $uri/ /index.html;
    }
}

Answer №1

Here is a suggestion for your configuration:

server {
    listen 8080 default_server;
    server_name _;

    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log main;

    # Include MIME types file if not defined previously
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    location /test/ {
        alias /home/vue_server/;
        try_files $uri $uri/ /test/index.html;
    }

    location / {
        return 301 /test/$uri;
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

html table displaying incorrect data while using dynamic data in vue 3

example status 1 Hello there! I'm trying to create a table (check out example status 1 for guidance). Here's the code snippet I am using: <table> <tr> <th>Product</th> <th>Price</th> <th>Av ...

vue-router default route for children

Currently, I am working on a Vue 2.x application and utilizing vue-router for routing purposes. In certain situations, I need to directly display a child vue. The template structure is as follows: | voice 1 | voice 2 | voice 3 | | submenu 1 | submen ...

JavaScript promises do not guarantee the execution of the loop

There was a block of Javascript code that I needed to modify. Initially, the code looked like this: if(!this.top3){ const promises = this.images.map((el, index) => { return this.getData(el.title, index); }); return Promise.all(promise ...

Please eliminate the forward slash (/) from the end of my route

Could anyone help me figure out how to remove the trailing slash at the end of routes in Nuxtjs? I attempted using the @nuxtjs redirect-module and setting the trailingSlash property to false, but instead of removing the slash, it adds multiple slashes at ...

Implementing dynamic option selection in Vue using JavaScript and v-model

Is there a way to manage the chosen value in a v-modeled select tag using vue.js? I created a jsFiddle demonstration, but unfortunately, it is not functioning correctly. This leads to my inquiry: vm.$set('selected', '1') // does not wo ...

Display the value in Vue.js as a price format while maintaining it as an integer

I have created a Vue component called "formatted-number" which takes in an integer value (e.g. 1234) and currently displays it as a string (e.g. "12.34") to represent a price in a textfield, with the appropriate "," or "." based on the country. However, I ...

Is it possible to implement sanctum on multiple Vue projects simultaneously?

Greetings! I am currently using Sanctum to authenticate users in the system. My goal is for a user who logs in to vue project num1 to also be automatically logged in to vue project num2. I attempted to implement this functionality using cookies like so: $ ...

Utilizing Google Analytics with Laravel Jetstream

Currently, I'm facing challenges with setting up Google Analytics to properly report data with the InertiaJS stack on Laravel Jetstream. My goal is to track individual page visits within this single-page application, but I'm uncertain about the a ...

Guide on implementing enums (or const) in VueJS

Seeking help on a seemingly simple task, I am trying to understand how to use "enums" in VueJS. In my file named LandingPage.js, I have the following code: const Form = { LOGIN: 0, SIGN_UP: 1, FORGOT_PASSWORD: 2, }; function main() { new Vue({ ...

Is there a way to rotate the custom marker icon in vue2-google-map?

After reading the documentation, I discovered that using path is the only way to rotate the marker. In an attempt to customize my marker, I created my own PNG image. However, I have been unsuccessful in overriding the CSS of the marker. I even tried to ov ...

Toggle visibility of column data on button click in a Vue and Laravel application

I'm struggling with a table setup where each row contains a 'show details' button. Inside the table, there is another div stacked, and I want to display the table in the specific column when the button is clicked. However, I'm having di ...

Guide to inserting a YouTube video or any iframe using vue-dompurify-html

Recently, I completed a blogging project in Nuxt where I utilized the quill text editor for managing content in the description field of my database. However, upon trying to display the blog post's description from the database using v-html, I encoun ...

Refreshing the page or directly loading it results in a blank screen being displayed

Despite researching various solutions to this common issue, none seem to work for me. Let's dive into it. I've developed a Vue 2 application integrated with Express running on AWS Amplify. When testing the app locally in 'dev' mode (np ...

What is the best way to showcase this information within my columns?

I'm facing an issue with VueJS. I have a large dataset that I want to display in columns in a specific order. How can I properly insert the code for this? Thank you for any assistance. [ { "sort": 0, "title": "My title", "description": ...

Setting up Paystack in a Laravel and Vue.js application: A comprehensive guide

I am in need of assistance. I have successfully set up Paystack on Laravel with Laravel Blade, but I am facing difficulties when trying to integrate Paystack with both Laravel and Vue.js. Vue communicates through an API endpoint, so I require guidance on ...

Tips for locating documents by their ID within an array of IDs retrieved from a different schema

I am currently dealing with 2 mongoose Schemas structured like this: var RecipeSchema = new Schema({ type: String, version: String, data: [{type: Schema.ObjectId, ref: 'Data'}] }); var Recipe = mongoose.model("Recipe", Re ...

Loading a Vue.js template dynamically post fetching data from Firebase storage

Currently, I am facing an issue with retrieving links for PDFs from my Firebase storage and binding them to specific lists. The problem arises because the template is loaded before the links are fetched, resulting in the href attribute of the list remainin ...

Leverage global functions when implementing Vue directives

Attempting to implement lodash methods (_.isEmpty) within Vue directives as shown below: <div class="post" v-for="post in posts"></div> ... <div class="comments" v-if="! _.isEmpty(post.comments)"> <div class="comment" v- ...

Encountering a 404 error when attempting to make an Axios post request

Utilizing Axios for fetching data from my backend endpoint has been resulting in a 404 error. Oddly enough, when I manually enter the URI provided in the error message into the browser, it connects successfully and returns an empty object as expected. Her ...

Convert form data into a JSON object using Vue.js

I'm attempting to generate a JSON object from the submitted form data. Fortunately, I've accomplished this using a variable. However, is there an alternative approach for creating a JSON object? Form <form @submit.prevent="submit"& ...