2012-06-27 30 views
11

CÂU HỎI: Tôi bị thiếu hoặc làm sai?nginx php5-fpm không thành công (2: Không có tệp hoặc thư mục nào như vậy)

Tôi đang cố gắng di chuyển ứng dụng Zend Framework đầy đủ chức năng từ Apache2 bằng mod_php5 sang nginx với php5-fpm. Tôi nhận được loại lỗi:

2012/06/27 12:08:04 [error] 1986#0: *1 open() "/var/www/public/sales/live-trials-json" failed (2: No such file or directory), client: *.*.*.*, server: www.mydomain.com, request: "POST /sales/live-trials-json HTTP/1.1", host: "www.mydomain.com", referrer: "https://www.mydomain.com/sales/live-trials"

Dưới đây là file cấu hình của tôi:

a)/etc/nginx/sites-enabled/www

server { 
    listen 80; 
    listen 443 default ssl; 

    server_name www.mydomain.com; 
    root /var/www/public; 

    ssl_certificate /etc/nginx/ssl/mydomain.crt; 
    ssl_certificate_key /etc/nginx/ssl/mydomain.key; 

    access_log /var/log/nginx/access.log; 
    error_log /var/log/nginx/error.log error; 

    index index.php index.phtml index.html; 

    location = /(favicon.ico|robots.txt) { 
    access_log off; 
    log_not_found off; 
    } 

    location ~* ^.+.(css|js|jpeg|jpg|gif|png|ico|xml) { 
    access_log off; 
    expires 30d; 
    } 

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

    location ~ /\.ht { 
    deny all; 
    } 

    location ~ \.php$ { 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    fastcgi_intercept_errors on; 
    include /etc/nginx/fastcgi_params; 
    } 
} 

b)/etc/nginx/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; 

c) /etc/php5/fpm/pool.d/www.conf

[www] 
user = www-data 
group = www-data 
listen = 127.0.0.1:9000 
pm = dynamic 
pm.max_children = 20 
pm.start_servers = 4 
pm.min_spare_servers = 2 
pm.max_spare_servers = 6 
chdir =/

d) ls-al/var/www

drwxr-xr-x 7 www-data www-data 4096 Jun 27 10:52 application 
drwxr-xr-x 5 www-data www-data 4096 Jun 27 10:52 library 
drwxr-xr-x 10 www-data www-data 4096 Jun 27 12:05 public 

e) nginx -V

nginx version: nginx/1.1.19 
TLS SNI support enabled 
configure arguments: 
    --prefix=/etc/nginx 
    --conf-path=/etc/nginx/nginx.conf 
    --error-log-path=/var/log/nginx/error.log 
    --http-client-body-temp-path=/var/lib/nginx/body 
    --http-fastcgi-temp-path=/var/lib/nginx/fastcgi 
    --http-log-path=/var/log/nginx/access.log 
    --http-proxy-temp-path=/var/lib/nginx/proxy 
    --http-scgi-temp-path=/var/lib/nginx/scgi 
    --http-uwsgi-temp-path=/var/lib/nginx/uwsgi 
    --lock-path=/var/lock/nginx.lock 
    --pid-path=/var/run/nginx.pid 
    --with-debug 
    --with-http_addition_module 
    --with-http_dav_module 
    --with-http_geoip_module 
    --with-http_gzip_static_module 
    --with-http_image_filter_module 
    --with-http_realip_module 
    --with-http_stub_status_module 
    --with-http_ssl_module 
    --with-http_sub_module 
    --with-http_xslt_module 
    --with-ipv6 
    --with-sha1=/usr/include/openssl 
    --with-md5=/usr/include/openssl 
    --with-mail 
    --with-mail_ssl_module 
    --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-auth-pam 
    --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-echo 
    --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-upstream-fair 
    --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-dav-ext-module 

f) php -v (đây là phiên bản cli, nhưng tôi thề tôi đang chạy nginx với fpm :)

PHP 5.3.10-1ubuntu3 with Suhosin-Patch (cli) (built: Apr 11 2012 17:25:33) 
Copyright (c) 1997-2012 The PHP Group 
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies 
+0

Tôi cũng đã thay đổi trong fastcgi_params mọi người phàn nàn trong bài viết dưới đây và vẫn không có gì: http://forum.nginx.org/read.php?11,214780,215113 – eistrati

+0

Đầu ra là gì từ 'ls -l/var/www/public/sales/live-trial- json'? – sarnold

+0

Nó không tồn tại, tất nhiên. Zend Framework viết lại các quy tắc và chạy bộ điều khiển và hành động tương ứng. Kiểm tra điều này: http://framework.zend.com/manual/en/learning.quickstart.intro.html – eistrati

Trả lời

8

Alright, sau dài và mệt mỏi, tôi đã quản lý để tìm ra sự điên rồ này. tất cả mọi thứ như vậy, tôi đã bắt đầu từ đầu và đây là những gì tôi đã học được:

Toàn bộ weirdness là ở đâu đó trong location ~* ... { ... }, vì vậy bất cứ ai có kinh nghiệm tốt hơn, xin vui lòng giải thích tại sao :-) Trong khi đó tôi sẽ quản lý tài sản và bộ nhớ đệm trên lớp ứng dụng.

tập tin cấu hình chức năng của tôi trông như thế này:

server { 
    listen 80; 
    listen 443 default ssl; 

    server_name www.mydomain.com; 
    root /var/www/public; 

    ssl_certificate /etc/nginx/ssl/mydomain.crt; 
    ssl_certificate_key /etc/nginx/ssl/mydomain.key; 

    access_log /var/log/nginx/access.log; 
    error_log /var/log/nginx/error.log error; 

    index index.php index.phtml index.html; 

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

    location ~ \.php$ { 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    fastcgi_intercept_errors on; 
    include /etc/nginx/fastcgi_params; 
    } 
} 

Cám ơn cố gắng, đặc biệt là @sarnold và @ Sergei-lomakov!

+0

điều này làm việc cho tôi, ngoại trừ tôi phải thay đổi một dòng: bình luận ra "bao gồm/etc/nginx/fastcgi_params;" và thêm "bao gồm fastcgi.conf;" – Saad

7

Cấu hình nginx của bạn hơi sai.

Vì đồng ý với các quy tắc của bạn, nginx cố truy cập/var/www/public/sales/live-trial-json không tồn tại.

Vì tôi không biết ứng dụng của bạn sử dụng điểm cuối nào, tôi khuyên bạn nên tạo hai vị trí nginx. Thứ nhất, đối với tất cả các file tĩnh (với regexp) tạo vị trí này:

location ~* ^.+.(css|js|jpeg|jpg|gif|png|ico|xml) { 
    access_log off; 
    expires 30d; 
    } 

Mọi thắc mắc khác nên được proxy để apache:

location/{ 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    fastcgi_intercept_errors on; 
    include /etc/nginx/fastcgi_params; 
    } 

Hãy chút thay đổi với quy tắc này:

location ~* ^/(favicon.ico|robots.txt)$ { 
    access_log off; 
    log_not_found off; 
    } 

Tất nhiên, bạn có thể để "cài đặt .ht" bị ảnh hưởng:

location ~ /\.ht { 
    deny all; 
    } 

Vì vậy, Final cấu hình sẽ là:

cuộc đấu tranh
server { 
    listen 80; 
    listen 443 default ssl; 

    server_name www.mydomain.com; 
    root /var/www/public; 

    ssl_certificate /etc/nginx/ssl/mydomain.crt; 
    ssl_certificate_key /etc/nginx/ssl/mydomain.key; 

    access_log /var/log/nginx/access.log; 
    error_log /var/log/nginx/error.log error; 

    index index.php index.phtml index.html; 

    location ~* ^/(favicon.ico|robots.txt)$ { 
    access_log off; 
    log_not_found off; 
    } 

    location ~* ^.+.(css|js|jpeg|jpg|gif|png|ico|xml) { 
    access_log off; 
    expires 30d; 
    } 

    location ~ /\.ht { 
    deny all; 
    } 

    location/{ 
    fastcgi_pass 127.0.0.1:9000; 
# I'm not sure that this setting is needed: 
#  fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    fastcgi_intercept_errors on; 
    include /etc/nginx/fastcgi_params; 
    } 


} 
+0

Không, đây không phải là câu trả lời đúng. Tôi đã sao chép xong tệp cấu hình của bạn và nó vẫn không hoạt động, cùng một lỗi. – eistrati

2

Như bạn đã nói, vấn đề của bạn là với

location ~* ^.+.(css|js|jpeg|jpg|gif|png|ico|xml) { 
    access_log off; 
    expires 30d; 
} 

này phù hợp với uri POST lại/bán hàng/live-thử nghiệm-json vì nó chưa được neo vào cuối đường dẫn uri, và. khớp với bất kỳ ký tự nào. Điều này có nghĩa là các trận đấu '-js'. Để khắc phục điều này, bạn chỉ cần thêm \ (để đối sánh chữ '.') Và $ (để neo kết quả khớp ở cuối đường dẫn uri):

location ~* \.(css|js|jpeg|jpg|gif|png|ico|xml)$ { 
    access_log off; 
    expires 30d; 
} 
+0

Câu trả lời của bạn là chính xác, nhưng nó chỉ là 50% của vấn đề. 50% vấn đề khác được chỉ ra bởi người trả lời trước, Sergei Lomakov ... Vì vậy, tôi không biết cách chia điểm thưởng giữa các bạn! Tôi đoán nó là công bằng để đưa họ cho Sergei, kể từ khi ông hướng dẫn các câu trả lời đúng :) – eistrati

Các vấn đề liên quan