nginx try_文件不工作?
我的目录:nginx try_文件不工作?,nginx,react-router,Nginx,React Router,我的目录: / |- static/ |- index.html // my pc page |- CKFM/ |-index.html // my mobile web app 更新: my nginx.conf完整版本: #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log
/
|- static/
|- index.html // my pc page
|- CKFM/
|-index.html // my mobile web app
更新:
my nginx.conf完整版本:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
ignore_invalid_headers off;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location ^~ /cooka {
proxy_pass http://localhost:8090 ;
}
location ^~ /cooka-search {
proxy_pass http://localhost:8089 ;
}
location ^~ /m/cooka {
proxy_pass http://localhost:8090 ;
}
location ^~ /CKFM {
try_files $uri $uri/ /CKFM/index.html;
}
location / {
root static;
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 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;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
我在/CKFM/folder中有一个基于react路由器的web应用程序
当我转到localhost/CKFM/it时,它可以工作,因为有一个index.html
但是当我转到localhost/CKFM/sign时/
它显示找不到404
我想要实现的是:
当转到localhost/CKFM/sigin时
它也将提供/CKFM/index.html
有关更多信息:
我的应用程序是react路由器应用程序
我正在按照文档配置nginx
我在一个全新下载的nginx中测试了try_文件配置,它可以正常工作
工作配置文件:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /CKFM {
try_files $uri /CKFM/index.html;
}
location / {
root 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 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;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
所以我猜我的一些配置破坏了try\u files指令…配置中的更改
location ^~ /CKFM {
root <your root folder>;
try_files $uri $uri/ /CKFM/index.html;
}
你也错过了;在这一行的末尾:更改配置
location ^~ /CKFM {
root <your root folder>;
try_files $uri $uri/ /CKFM/index.html;
}
你也错过了;在这行末尾:以下是我的配置谢谢@gutch@Max p
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
}
#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;
}
}
以下是我的配置谢谢@gutch@Max p
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
}
#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;
}
}
有500个错误!当访问localhost/CKFM/时,我更新了我的问题,你能检查一下吗。我猜我的一些配置与try_文件冲突,但我不知道您的服务器根html的根目录是哪个;或者对于location location/CKFM{root html;try_files$uri/CKFM/index.html;}root是CKFMI的父目录,必须在最后一个位置添加=404作为另一个参数:{try_files$uri/index.html$is_args$args=404}错误500!当访问localhost/CKFM/时,我更新了我的问题,你能检查一下吗。我猜我的一些配置与try_文件冲突,但我不知道您的服务器根html的根目录是哪个;或者对于location location/CKFM{root html;try_files$uri/CKFM/index.html;}root是CKFMI的父目录,必须在最后一个位置添加=404作为另一个参数:{try_files$uri/index.html$is_args$args=404}