2017-07-03 65 views
0

我對https://github.com/coryhouse/react-slingshot有反應的應用程序庫。 我有網址:/關於 如果我直接通過開發模式或本地主機上的生產直接到這個網址它工作正常。通過nginx的 但在EC2實例我有錯誤:ReactJS應用程序EC2路由器404

404 Not Found

nginx/1.10.3 (Ubuntu)

這裏是我的nginx的conf:

server { 
    listen 80; 
    server_name example.com; 
    return 301 https://$server_name$request_uri; 
} 

server { 
     listen 443 ssl; 
     root /home/ubuntu/www/example; 
     index index.html index.htm; 

    add_header Strict-Transport-Security "max-age=31536000";   
     ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; 
     ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; 
     ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
     ssl_prefer_server_ciphers on; 
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:AES256+ECDHE'; 

     # Make site accessible from http://localhost/ 
     server_name example.com; 
     location/{ 
       # First attempt to serve request as file, then 
       # as directory, then fall back to displaying a 404. 
       try_files $uri $uri/ =404; 
       # Uncomment to enable naxsi on this location 
       # include /etc/nginx/naxsi.rules 
     } 
} 

如何正確配置呢?謝謝!

回答

0

嘿我剛剛發現終於在水木清華互聯網:)

https://gkedge.gitbooks.io/react-router-in-the-real/content/nginx.html

工作正常。

我錯過了好位置:

location ~* \.(?:manifest|appcache|html?|xml|json)$ { 
     expires -1; 
     # access_log logs/static.log; # I don't usually include a static log 
    } 

    location ~* \.(?:css|js)$ { 
     try_files $uri =404; 
     expires 1y; 
     access_log off; 
     add_header Cache-Control "public"; 
    } 

    # Any route containing a file extension (e.g. /devicesfile.js) 
    location ~ ^.+\..+$ { 
     try_files $uri =404; 
    } 

    # Any route that doesn't have a file extension (e.g. /devices) 
    location/{ 
     try_files $uri $uri/ /index.html; 
    }