A
A
Alexey2019-02-16 14:20:29
Nginx
Alexey, 2019-02-16 14:20:29

Nginx - Nuxt setting request proxying in dev mode?

Client scripts are not loaded in dev mode. The application normally runs on port 3000. Requests are processed by nginx and proxies them to the application server. In production mode, everything is fine, the build is assembled, the files physically exist and are located at the appropriate paths. The problem starts when working in dev mode, as we know, in this case, the files are not created on disk, but simply stored in memory, and the application server decides what content to give when certain scripts are requested (like https://site.com/ _nuxt/runtime.js https://site.com/_nuxt/vendors.app.js).And all this works correctly only when requests go directly to the application server. Those. for example, we standardly launch a server on a local machine and access localhost:3000 from the browser, everything will work as expected - the server generated html, gave it to the browser, it in turn builds the dom, detects scripts, requests them, receives them. In the case of proxying, this does not work. Maybe someone knows how it is configured, if it is configured at all? To clarify, nginx proxies all requests to the application server. Below, just in case, I am attaching a simplified listing of the host configuration, it is conceptually configured in this way, everything that has been removed does not change the essence.

server
{
    listen 443 default_server ssl http2;
    listen [::]:443 ssl http2;

    root /path/to/webroot;

    server_name site.com;
    charset utf-8;

    include settings/ssl;

    location / {
        proxy_redirect                       off;

        proxy_set_header Host                $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;
        proxy_set_header Upgrade             $http_upgrade;
        proxy_set_header Connection          'upgrade';

        proxy_pass                           http://127.0.0.1:3000;
        proxy_cache_bypass                   $http_upgrade;
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question