Jea*_*ean 3 nginx reactjs react-router
我有一个应用程序,有两个路由器主页和结果。在主页中,我必须转到我们的授权微服务并返回到我的反应应用程序,返回结果页面,但是 result.html 文件不存在,因为是反应应用程序,所以我收到 404 错误。
我正在我的 nginx 上尝试以下配置:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
# Any route that doesn't have a file extension (e.g. /devices)
location / {
try_files $uri $uri/ /results.html;
}
}
Run Code Online (Sandbox Code Playgroud)
但仍然无法正常工作。请提出任何建议。
这是我在不使用 expressjs 服务器的情况下解决这个问题的方法:
这是我的 nginx 配置文件:
# pushState friendly!
# The setup:
# * website name is `_`
# * javascript app is located at `/app`
charset utf-8;
tcp_nopush on;
tcp_nodelay off;
client_header_timeout 10s;
client_body_timeout 10s;
client_max_body_size 128k;
reset_timedout_connection on;
gzip on;
gzip_types
text/css
text/javascript
text/xml
text/plain
application/javascript
application/x-javascript
application/json
application/xml
application/rss+xml
application/atom+xml
font/truetype
font/opentype
image/svg+xml;
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
# To make sure any assets can get through :)
location / {
try_files $uri @rewrites;
}
# If no asset matches, send it to your javascript app. Hopefully it's a route in the app!
location @rewrites {
rewrite ^(.+)$ /index.html last;
}
}
Run Code Online (Sandbox Code Playgroud)