我有一个我想显示的特定路径的应用程序。不过,后端使用了类似的路径。这是旧版应用程序,其他静态文件使用不同的端点显示。
我无法正确显示内容。我要么显示旧文件,要么破坏相似的路径,或者NGINX在路径的末尾附加无穷大/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;
}
}
答案 0 :(得分:0)
结果是我得到了奇怪的重定向。另外,我的react应用有一个静态文件夹,第二个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;
}
}