带有 Nginx 反向代理的 React App 不显示 /swagger ; /redoc

带有 Nginx 反向代理的 React App 不显示 /swagger ; /redoc

所以我一直在尝试设置 Swagger 以在 /swagger/ 上工作,在我们切换到域之前它工作正常。我对 nginx 及其反向代理不太熟悉。如果有人能帮忙,我会分享我的设置。它实际上打开了页面,但全是白色的,/redoc/(Redis)也是如此。

Nginx配置文件

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;
    }

例如,/ht/(健康检查)运行正常

后端的urls.py:

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

如果您需要任何其他文件,请告诉我,我愿意分享它们,我只是用 mysite.com 等虚拟数据替换敏感数据

提前致谢!

编辑:我刚刚注意到,在“网络”选项卡中,它显示所有 CSS、JS 文件都“需要启用 Javascript 才能运行此应用程序”,/redoc 也是如此,并且控制台日志还会抛出以下信息:“未捕获的语法错误:意外的令牌‘<’”用于 JS 文件。

我忘了说这是一个 React App,但 App 本身运行良好。后端是 Python/Django,所以我一直在尝试设置 Swagger 以在 /swagger/ 上工作,在我们切换到域之前,它运行良好。我对 nginx 及其反向代理不太熟悉。如果有人能帮忙,我会分享我的设置。它实际上打开了页面,但全是白色的,/redoc/(Redis)也是如此。

Nginx配置文件

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;
    }

例如,/ht/(健康检查)运行正常

后端的urls.py:

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

如果您需要任何其他文件,请告诉我,我愿意分享它们,我只是用 mysite.com 等虚拟数据替换敏感数据

提前致谢!

编辑:我刚刚注意到,在“网络”选项卡中,它显示所有 CSS、JS 文件都“需要启用 Javascript 才能运行此应用程序”,/redoc 也是如此,并且控制台日志还会抛出以下信息:“未捕获的语法错误:意外的令牌‘<’”用于 JS 文件。

我忘了说明这是一个 React App,但 App 本身运行良好。后端使用 Python/Django

相关内容