Tôi đang chuyển ứng dụng phản ứng của tôi từ webpack-dev-server sang nginx.React-router và nginx
Khi tôi đi đến url gốc "localhost: 8080/login" Tôi chỉ đơn giản là có được một 404 và trong nhật ký nginx của tôi, tôi thấy rằng nó đang cố gắng để có được:
my-nginx-container | 2017/05/12 21:07:01 [error] 6#6: *11 open() "/wwwroot/login" failed (2: No such file or directory), client: 172.20.0.1, server: , request: "GET /login HTTP/1.1", host: "localhost:8080"
my-nginx-container | 172.20.0.1 - - [12/May/2017:21:07:01 +0000] "GET /login HTTP/1.1" 404 169 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:53.0) Gecko/20100101 Firefox/53.0" "-"
tôi nên tìm một trường hợp sửa chữa ?
chút Router của tôi trong phản ứng trông như thế này:
render(
<Provider store={store}>
<MuiThemeProvider>
<BrowserRouter history={history}>
<div>
Hello there p
<Route path="/login" component={Login} />
<App>
<Route path="/albums" component={Albums}/>
<Photos>
<Route path="/photos" component={SearchPhotos}/>
</Photos>
<div></div>
<Catalogs>
<Route path="/catalogs/list" component={CatalogList}/>
<Route path="/catalogs/new" component={NewCatalog}/>
<Route path="/catalogs/:id/photos/" component={CatalogPhotos}/>
<Route path="/catalogs/:id/photos/:photoId/card" component={PhotoCard}/>
</Catalogs>
</App>
</div>
</BrowserRouter>
</MuiThemeProvider>
</Provider>, app);
Và tập tin nginx của tôi như thế này:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
server {
listen 8080;
root /wwwroot;
location/{
root /wwwroot;
index index.html;
try_files $uri $uri/ /wwwroot/index.html;
}
}
}
EDIT:
Tôi biết rằng hầu hết các thiết lập trình bởi vì khi Tôi đi đến localhost: 8080 mà không cần đăng nhập Tôi cũng nhận được trang đăng nhập. đây không phải là thông qua một chuyển hướng đến localhost: 8080/login - đó là một số mã phản ứng.
Các tham số cho 'try_files' phải là URI và không phải là tên đường dẫn. Hãy thử: 'try_files $ uri $ uri//index.html;' –
@RichardSmith OK ... Tôi thấy nó là tên đường dẫn đến tệp index.html. Tôi đã thử thay đổi nó thành những gì bạn đề nghị - nhưng nhận được kết quả tương tự. ##/wwwroot/login "thất bại (2: Không có tập tin hoặc thư mục nào) ## bạn có gợi ý nào khác không. Tôi sẽ đi sâu vào nó ... – martin