【发布时间】:2021-02-09 18:08:46
【问题描述】:
我想按照以下说明访问其中一个 react 项目。
https://my.domain.com/app1 ==> HTTP://localhost:7001
以下是 Nginx 配置:
server {
listen 80;
server_name my.domain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/my.domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/my.domain.com/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
server_name my.domain.com;
error_log /var/log/nginx/my.domain.com.err;
access_log /var/log/nginx/my.domain.com.log;
location /app1 {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
add_header Pragma "no-cache";
add_header Cache-Control "no-cache";
proxy_pass http://localhost:7001/;
proxy_redirect default;
sub_filter_types *;
sub_filter 'action="/' 'action="/app1/';
sub_filter 'href="/' 'href="/app1/';
sub_filter 'src="/' 'src="/app1/';
sub_filter_once off;
}
}
问题是某些源文件由https://my.domain.com/app1/... 响应,但有些由https://my.domain.com/... 响应,第二个源文件无法访问并给出HTTP 404 错误。
例如,以下来源已回复为HTTP 200:
https://my.domain.com/app1/static/css/main.091g2s3f.chunk.css
https://my.domain.com/app1/static/js/2.29c551h6.chunk.js
以下回复为HTTP 404:
https://my.domain.com/media/contact-title.png
https://my.domain.com/static/media/Yekan.05744gh2.woff
https://my.domain.com/logo.svg
有什么想法吗? 提前致谢。
我做了什么但没有解决:
我确实配置了Nginx rewrite,简单的proxy_pass和regex,但是问题没有解决,另外,我得到的所有回复都是HTTP 404。
【问题讨论】:
标签: reactjs nginx nginx-reverse-proxy