2017-05-13 11 views
9

मैं अपने प्रतिक्रिया ऐप को वेबपैक-देव-सर्वर से nginx में बदल रहा हूं।प्रतिक्रिया-राउटर और nginx

जब मैं जड़ यूआरएल के लिए जाना "स्थानीय होस्ट: 8080/के लिए लॉग इन" मैं बस एक 404 हो और मेरी nginx लॉग में मुझे लगता है कि इसे पाने के लिए कोशिश कर रहा है:

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" "-" 

मैं एक के लिए कहाँ देखना चाहिए ठीक कर ?

प्रतिक्रिया में मेरे रूटर बिट इस तरह दिखता है:

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); 

और इस तरह मेरे nginx फ़ाइल:

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; 
     } 


    } 
} 

संपादित करें:

मुझे पता है कि सेटअप के सबसे क्योंकि जब काम करता है मैं लोकलहोस्ट पर जाता हूं: 8080 लॉग इन किए बिना मुझे लॉगिन पेज भी मिलता है। यह स्थानीयहोस्ट पर रीडायरेक्ट के माध्यम से नहीं है: 8080/लॉगिन - यह कुछ प्रतिक्रिया कोड है।

+1

'try_files' के पैरामीटर यूआरआई होना चाहिए और पथनाम नहीं होना चाहिए। आज़माएं: 'try_files $ uri $ uri//index.html; ' –

+0

@ रिचर्डस्मिथ ठीक है ... मैंने इसे index.html फ़ाइल के पथनाम के रूप में देखा है। मैंने इसे आपके द्वारा सुझाए गए अनुसार बदलने की कोशिश की है - लेकिन एक ही परिणाम प्राप्त करना। ##/wwwroot/login "असफल रहा (2: ऐसी कोई फ़ाइल या निर्देशिका नहीं) ## क्या आपके पास अन्य सुझाव हैं। मैं इसे tonite में गोता लगाऊंगा ... – martin

उत्तर

17

अपने nginx config में स्थान ब्लॉक किया जाना चाहिए:

location/{ 
    try_files $uri /index.html; 
} 

समस्या यह है कि index.html फ़ाइल काम करने के लिए अनुरोध, पर आप अभी nginx सूचकांक करने के लिए अन्य अनुरोध अग्रेषित करने के लिए कह रही है नहीं कर रहे हैं है। एचटीएमएल फाइल भी।

+0

आप सर टोबी ने मुझे गुगलिंग के बहुत से बचाया! – Nopzen