Score:2

React App with Nginx reverse proxy not displaying /swagger ; /redoc

dk flag

So I've been trying to set up Swagger to work on /swagger/, it was working fine until we switched to a domain. I'm not that experienced with nginx and it's reverse proxy. I will share my settings, if anyone could help. It actually opens the page, but it's all white, same goes with /redoc/ (Redis).

Nginx.conf

events {
worker_connections 768;
multi_accept       on;
}

http {

large_client_header_buffers 16 5120k;
fastcgi_read_timeout 900;
proxy_read_timeout 900;   
proxy_connect_timeout 900;
proxy_send_timeout 900;    

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens off;

proxy_buffer_size   128k;
proxy_buffers   4 256k;
proxy_busy_buffers_size   256k;

include /etc/nginx/mime.types;
default_type application/octet-stream;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;

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

gzip on;

proxy_http_version      1.1;
proxy_set_header        Upgrade $http_upgrade;
proxy_set_header        Connection "upgrade";
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        Host $http_host;
proxy_intercept_errors  on;

server {

    client_max_body_size 250M;
    listen 80;
    server_name mysite.com;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

        location / {
            return 301 https://$host$request_uri;
    }
}

server {

    client_max_body_size 250M;
    listen 443 ssl;
    server_name mysite.com;

    ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location / {
        proxy_pass http://mysite:3000/;
        proxy_redirect off;
        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        Host $http_host;
        proxy_intercept_errors  on;
    }

    location /ht/ {
        proxy_pass http://mysite:8000/ht/;
        proxy_redirect off;
        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        Host $http_host;
        proxy_intercept_errors  on;
    }

    location /swagger/ {
        proxy_pass http://mysite:8000/swagger/;
        proxy_redirect off;
        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        Host $http_host;
        proxy_intercept_errors  on;
    }

For example, /ht/ (health check) is working just fine

urls.py in backend:

urlpatterns = [ 
url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema- 
swagger-ui')]

Please tell me if you need any other files, I'm willing to share them, I just replace sensitive data with dummy data like mysite.com

Thanks in advance!

Edit: I've just noticed that in Network tab, it shows for all CSS, JS files that "Javascript needs to be enabled to run this app", same goes for /redoc and also console log throws this: "Uncaught SyntaxError: Unexpected token '<'" for the JS files.

I've forgot to note it's a React App, but the App itself is working fine. Backend is in Python/Django So I've been trying to set up Swagger to work on /swagger/, it was working fine until we switched to a domain. I'm not that experienced with nginx and it's reverse proxy. I will share my settings, if anyone could help. It actually opens the page, but it's all white, same goes with /redoc/ (Redis).

Nginx.conf

events {
worker_connections 768;
multi_accept       on;
}

http {

large_client_header_buffers 16 5120k;
fastcgi_read_timeout 900;
proxy_read_timeout 900;   
proxy_connect_timeout 900;
proxy_send_timeout 900;    

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens off;

proxy_buffer_size   128k;
proxy_buffers   4 256k;
proxy_busy_buffers_size   256k;

include /etc/nginx/mime.types;
default_type application/octet-stream;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;

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

gzip on;

proxy_http_version      1.1;
proxy_set_header        Upgrade $http_upgrade;
proxy_set_header        Connection "upgrade";
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        Host $http_host;
proxy_intercept_errors  on;

server {

    client_max_body_size 250M;
    listen 80;
    server_name mysite.com;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

        location / {
            return 301 https://$host$request_uri;
    }
}

server {

    client_max_body_size 250M;
    listen 443 ssl;
    server_name mysite.com;

    ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location / {
        proxy_pass http://mysite:3000/;
        proxy_redirect off;
        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        Host $http_host;
        proxy_intercept_errors  on;
    }

    location /ht/ {
        proxy_pass http://mysite:8000/ht/;
        proxy_redirect off;
        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        Host $http_host;
        proxy_intercept_errors  on;
    }

    location /swagger/ {
        proxy_pass http://mysite:8000/swagger/;
        proxy_redirect off;
        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        Host $http_host;
        proxy_intercept_errors  on;
    }

For example, /ht/ (health check) is working just fine

urls.py in backend:

urlpatterns = [ 
url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema- 
swagger-ui')]

Please tell me if you need any other files, I'm willing to share them, I just replace sensitive data with dummy data like mysite.com

Thanks in advance!

Edit: I've just noticed that in Network tab, it shows for all CSS, JS files that "Javascript needs to be enabled to run this app", same goes for /redoc and also console log throws this: "Uncaught SyntaxError: Unexpected token '<'" for the JS files.

I've forgot to note it's a React App, but the App itself is working fine. Backend is in Python/Django

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.