处理具有不同块的类似位置

问题描述 投票:0回答:1

我有一个反应应用程序,我想显示特定的路径。但是,后端使用了类似的路径。这是一个遗留应用程序,其他静态文件使用不同的端点显示。

我无法正确显示内容。我正在显示旧文件,或者我正在破坏类似的路径,或者NGINX在路径的末尾附加了infinity /index.html。

如果这听起来令我感到困惑,那么下面的插图可能会有所帮助:

location / -> leave uwsgi to handle the requests
location /static/ -> serve static folder
location /request/ -> serve new react app
location /request_auth/ -> serve new react app
location /request_auth/token... -> leave uwsgi to handle the requests

这就是我现在所拥有的,它不起作用!

server {
    listen       80;
    server_name  myapp.com;

    root /var/www/myapp/static/;

    location / {
        uwsgi_pass unix:///var/www/myapp/uwsgi/uwsgi.sock;
        include uwsgi_params;
        uwsgi_param HTTPS on;
    }

    # I think I can remove this block...
    location ^~ /static/ {
        alias /var/www/myapp/static/;
    }

    location ^~ /request/ {
        alias /var/www/myapp/reactstatic/;
    }

    # from down here it is not working properly. I've tried using
    # location =/request_auth/
    # location /request_auth/ 
    # and other variations in the other block as well. All unsuccessful 
    location ^~ /request_auth/ {
        alias /var/www/myapp/reactstatic/;
    }

    location ~^/request_auth/[a-zA-Z0-9]+ {
        uwsgi_pass unix:///var/www/myapp/uwsgi/uwsgi.sock;
        include uwsgi_params;
        uwsgi_param HTTPS on;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
nginx nginx-location
1个回答
0
投票

结果我得到了奇怪的重定向。此外,我的反应应用程序有一个静态文件夹,第二个uwsgi试图处理它。

这就是我所做的并且它正在发挥作用,但我确信有更好的解决方案。

server {
    listen       80;
    server_name  myapp.com;

    root /var/www/myapp/static/;

    location / {
        uwsgi_pass unix:///var/www/myapp/uwsgi/uwsgi.sock;
        include uwsgi_params;
        uwsgi_param HTTPS on;
    }

    # I think I can remove this block...
    location ^~ /static/ {
        alias /var/www/myapp/static/;
    }

    location ^~ /request/ {
        alias /var/www/myapp/reactstatic/;
    }
    location ^~ /request/ {
        alias /var/www/myapp/reactstatic/static;
    }

    location ^~ /request_auth/ {
        alias /var/www/myapp/reactstatic/;
    }
    location ^~ /request_auth/ {
        alias /var/www/myapp/reactstatic/static;
    }

    location ~^/request_auth/[a-zA-Z0-9]+ {
        uwsgi_pass unix:///var/www/myapp/uwsgi/uwsgi.sock;
        include uwsgi_params;
        uwsgi_param HTTPS on;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.