2013-02-13 32 views
6

मैं सिर्फ Nginx की स्थापना कर रहे हैं, और मैं इसे उपयोग करने के लिए एक Laravel एप्लिकेशन की मेजबानी के लिए कोशिश कर रहा हूँ, लेकिन मैं 2 समस्याओं में भाग गया।Laravel साथ Nginx मापदंडों खाली

  1. GET पद्धति के लिए, मैं हमेशा एक अतिरिक्त पैरामीटर मेरी आदानों में मिलता है।
    • मेरे परीक्षण करने के लिए पोस्टमैन (क्रोम) का उपयोग करके, मैंने गंतव्य यूआरएल और मेरे वांछित पैरामीटर सेट किए और अनुरोध भेज दिया। उत्पादन है कि मैं पाने के लिए, यह हमेशा REQUEST_URI जो ऐसा नहीं होना चाहिए शामिल हैं। उदाहरण आउटपुट:

Array (
    [/api/user] => // This shouldn't be here 
    [test] => test 
) 
  1. मेरे मानकों (ऊपर) को नष्ट करने के लिए होगा नहीं शो या डाल, बिल्कुल, और पोस्ट के लिए मैं केवल REQUEST_URI
मिलेगा

Nginx vhost (इसके बाद Setting up Laravel w/ Nginx)

server { 
    server_name local.test.com; 
    root /var/www/test/public; 

    location/{ 
     index index.php index.html index.htm; 
    } 

    # serve static files directly 
    location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { 
     access_log off; 
     expires max; 
    } 

    # removes trailing slashes (prevents SEO duplicate content issues) 
    if (!-d $request_filename) { 
     rewrite ^/(.+)/$ /$1 permanent; 
    } 

    # unless the request is for a valid file (image, js, css, etc.), send to bootstrap 
    if (!-e $request_filename) { 
     rewrite ^/(.*)$ /index.php?/$1 last; 
     break; 
    } 

    # catch all 
    error_page 404 /index.php; 

    # The PHP Inclusion Block 
    # include /etc/nginx/includes/php; 
    location ~ \..*/.*\.php$ { 
     # I'm pretty sure this stops people trying to traverse your site to get to other PHP files 
     return 403; 
    } 

    #location ~ \.php$ { 
    location ~ \.php(.*)$ { 
     try_files $uri =404; 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     include /etc/nginx/fastcgi_params; 
    } 

# Deny Any Access to .htaccess Files That May Be Present (not usually in issue in Laravel) 
# include /etc/nginx/includes/deny_htaccess; 
location ~ /\.ht 
{ 
    deny all; 
} 

    error_log /var/www/logs/test-error.log; 
} 

fastcgi_params:

fastcgi_param QUERY_STRING   $query_string; 
fastcgi_param REQUEST_METHOD   $request_method; 
fastcgi_param CONTENT_TYPE   $content_type; 
fastcgi_param CONTENT_LENGTH   $content_length; 

fastcgi_param SCRIPT_FILENAME   $request_filename; 
fastcgi_param SCRIPT_NAME    $fastcgi_script_name; 
fastcgi_param REQUEST_URI    $request_uri; 
fastcgi_param DOCUMENT_URI   $document_uri; 
fastcgi_param DOCUMENT_ROOT   $document_root; 
fastcgi_param SERVER_PROTOCOL   $server_protocol; 

fastcgi_param GATEWAY_INTERFACE  CGI/1.1; 
fastcgi_param SERVER_SOFTWARE   nginx/$nginx_version; 

fastcgi_param REMOTE_ADDR    $remote_addr; 
fastcgi_param REMOTE_PORT    $remote_port; 
fastcgi_param SERVER_ADDR    $server_addr; 
fastcgi_param SERVER_PORT    $server_port; 
fastcgi_param SERVER_NAME    $server_name; 

#fastcgi_param HTTPS     $https; 

# PHP only, required if PHP was built with --enable-force-cgi-redirect 
fastcgi_param REDIRECT_STATUS   200; 

fastcgi_connect_timeout     60; 
fastcgi_send_timeout     180; 
fastcgi_read_timeout     180; 
fastcgi_buffer_size      128k; 
fastcgi_buffers 4      256k; 
fastcgi_busy_buffers_size    256k; 
fastcgi_temp_file_write_size   256k; 
fastcgi_intercept_errors    on; 

nginx.conf केवल 1 बात बदल गया है, और कहा कि 15

65 से keepalive_timeout है तो मैं पूरी तरह से है कोई सुराग नहीं है, जहां यह सब बात गलत हो जाता है। लेकिन मैं उल्लेख करने के लिए, कि एक और 2 वातावरण मेरे पास है (Lighttpd के साथ एक और Apache2 के साथ अन्य) पर अनुप्रयोग पूरी तरह से काम करता है की क्या ज़रूरत है।

से मैं क्या देखा है, अपने सभी निम्न कोड करने के लिए कम:

# unless the request is for a valid file (image, js, css, etc.), send to bootstrap 
if (!-e $request_filename) { 
    rewrite ^/(.*)$ /index.php?/$1 last; 
    break; 
} 

किस काम कर देगा ... और अतिरिक्त पैरामीटर

उत्तर

5

यह सबसे अच्छा अनावश्यक से बचने के लिए है जोड़ने

तुम सब Laravel के लिए की जरूरत है:

अपने nginx विन्यास ( Nginx Pitfalls देखें), विशेष रूप से एक के बाद एक Laravel सामने नियंत्रक से अनुरोध पारित करने के लिए जिम्मेदार है में पुनर्लेखन
location/{ 
    index index.php index.html index.htm; 
    try_files $uri $uri/ index.php?$query_string; 
} 

सबसे पहले जो सीधे फ़ाइल तक पहुंचने का प्रयास करता है, फिर एक निर्देशिका, और यदि न तो मौजूद है तो यह index.php के अनुरोध को पास करता है। $query_string पास किया जा सके कि के रूप में $_GET डेटा कि अन्यथा खो जाए शामिल होंगे महत्वपूर्ण है।

और यहाँ अपने ही FastCGI विन्यास टुकड़ा है:

location ~ \.php$ { 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; 
    include  fastcgi_params; 
} 

के रूप में अप्रत्याशित इनपुट के लिए, जिस तरह से अपने वर्तमान फिर से लिखने का काम करता है हो सकता है, लेकिन निश्चित रूप से कह करने के लिए, तुम क्या outputting रहे हैं?

+0

'dd के साथ मेरे लिए काम करता है (इनपुट :: सभी());' यह है कि मैं क्या 'है मीटर outputting ... और नहीं, यह नहीं है 'इनपुट :: सभी()' कि अवांछित पैरामीटर – Alex

+0

ठीक निर्धारित किया है। सुझाए गए कॉन्फ़िगरेशन आज़माएं और मुझे बताएं कि यह ऐसा करता है या नहीं। – Gargron

+0

बस इसे करने की कोशिश की, 'रीराइट नियम युक्त if's टिप्पणी करके, और अब मैं पर मदद के लिए सभी – Alex

1

अपने config से:

rewrite ^/(.*)$ /index.php?/$1 last; 
यहाँ

आप /index.php?/$1 (जैसे /index.php?/some/path) के लिए एक रीडायरेक्ट की है।

fastcgi_split_path_info ^(.+\.php)(/.+)$; 

और यहां आप ^(.+\.php)(/.+)$ regex (जैसे /index.php/some/path) द्वारा पथ गिरा।

आप अंतर पर ध्यान है?

+0

काम नहीं करता है मैं वास्तव में 'fastcgi_spli' हिस्सा निकाल दिया और अब मैं मानकों मिलता है, लेकिन मैं अभी भी' [/ API/उपयोगकर्ता] है =>// यह here' समस्या – Alex

+0

नहीं होना चाहिए मैं http://stackoverflow.com/questions/8856664/setting-up-laravel-w-nginx पीछा किया और सिर्फ एक छोटा सा – Alex

+0

addapted लेकिन आप nginx कि जिस तरह से कॉन्फ़िगर किया है। आपका 'पुनः लिखना ^/(। *) $ /index.php?/$1 अंतिम; पैरामीटर के पथ को जोड़ने के लिए जिम्मेदार है। – VBart

1

यह मेरे लिए काम करता है:

location/{ 
    index index.php; 
    try_files $uri $uri/ /index.php?q=$uri&$args; 
} 

location ~ \.php$ { 

    include  fastcgi_params; 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_index index.php; 

    fastcgi_split_path_info     ^(.+\.php)(/.+)$; 
    fastcgi_param PATH_INFO     $fastcgi_path_info; 
    fastcgi_param PATH_TRANSLATED   $document_root$fastcgi_path_info; 
    fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name; 

} 
+0

मुझे नहीं लगता कि लार्वेल को 'q' पैरामीटर की उम्मीद है, इसे पहले नहीं देखा है। लेकिन इसे सीआई – Alex

+0

में देखा हां, मैंने इसे 'q' के बिना परीक्षण किया है और यह ठीक काम करता है। तो 'try_files $ uri $ uri//index.php? $ Args; 'काम करता है। –

0

यह एक विन्यास कि nginx और Laravel

server { 

    listen 80; 
    server_name sub.domain.com; 
    set $root_path '/var/www/html/application_name/public'; 
    root $root_path; 

    index index.php index.html index.htm; 

    try_files $uri $uri/ @rewrite; 

    location @rewrite { 
     rewrite ^/(.*)$ /index.php?_url=/$1; 
    } 

    location ~ \.php { 

     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index /index.php; 

     include /etc/nginx/fastcgi_params; 

     fastcgi_split_path_info  ^(.+\.php)(/.+)$; 
     fastcgi_param PATH_INFO  $fastcgi_path_info; 
     fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ { 
     root $root_path; 
    } 

    location ~ /\.ht { 
     deny all; 
    } 

}