简体   繁体   English

如何为zendframework2正确配置为Nginx和Apache

[英]How to configure correctly to nginx and apache for zendframework2

ENV ENV

CentOS 6.5 x86_64 PHP 5.6.3 httpd 2.4.10 Nginx 1.6.2 ZendFramework2.3.3 CentOS 6.5 x86_64 PHP 5.6.3 httpd 2.4.10 Nginx 1.6.2 ZendFramework2.3.3

Target 目标

Install ZF2 Skeleton Application 安装ZF2 Skeleton应用程序

Now 现在

I configure nginx to pass php files to apache. 我将nginx配置为将php文件传递给Apache。 I configure zf2 skeleton application into a virtual host, either in nginx or apache. 我在nginx或apache中将zf2骨架应用程序配置为虚拟主机。 I install zendframework2.3.3 manually. 我手动安装zendframework2.3.3。 I can access website normally by 127.0.0.1:38082(configured by httpd). 我可以通过127.0.0.1:38082(由httpd配置)正常访问网站。 However, when I access the website by 127.0.0.1:8082(configured by nginx), I got 404 error as below. 但是,当我通过127.0.0.1:8082(由nginx配置)访问网站时,出现以下404错误。 Anyone can give me some advice? 有人可以给我一些建议吗? Thanks. 谢谢。

My Configuration 我的配置

Nginx vhost Nginx虚拟主机

server {
    listen       8082;
    server_name  www.eg.m;

    #charset koi8-r;

    access_log  logs/eg.access.log  main;

    location / {
        root   /data/webapp/www/zf-app/public;
        index  index.php index.html index.htm Default.html Default.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    location ~ \.php$ {
        proxy_pass   http://127.0.0.1:38082;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

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

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}

}

httpd vhost httpd虚拟主机

Listen 38082

<VirtualHost *:38082>
    ServerAdmin w@gmail.com
    DocumentRoot "/data/webapp/www/zf-app/public"
    ServerName www.eg.m
    ServerAlias eg.m
    ErrorLog "logs/eg.m-error_log"
    CustomLog "logs/eg.m-access_log" common

    SetEnv ZF2_PATH "/data/webapp/www/ZendFramework-2.3.3/library"
    SetEnv APPLICATION_ENV "development"

    <Directory /data/webapp/www/zf-app/public>
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all

    </Directory>

</VirtualHost>

I got Error 我有错误

A 404 error occurred
Page not found.

The requested URL could not be matched by routing.
No Exception available

在此处输入图片说明

log 日志

apache Logs when directly from apache with 127.0.0.1:38082 apache从127.0.0.1:38082直接从apache登录时

error-log 错误日志

[Mon Dec 22 19:52:37.100637 2014] [authz_core:debug] [pid 17524:tid 139805499234048] mod_authz_core.c(802): [client 127.0.0.1:38934] AH01626: authorization result of Require all granted: granted
[Mon Dec 22 19:52:37.100694 2014] [authz_core:debug] [pid 17524:tid 139805499234048] mod_authz_core.c(802): [client 127.0.0.1:38934] AH01626: authorization result of <RequireAny>: granted
[Mon Dec 22 19:52:37.184903 2014] [authz_core:debug] [pid 17524:tid 139805490841344] mod_authz_core.c(802): [client 127.0.0.1:38934] AH01626: authorization result of Require all granted: granted, referer: http://127.0.0.1:38082/
[Mon Dec 22 19:52:37.184927 2014] [authz_core:debug] [pid 17524:tid 139805490841344] mod_authz_core.c(802): [client 127.0.0.1:38934] AH01626: authorization result of <RequireAny>: granted, referer: http://127.0.0.1:38082/
[Mon Dec 22 19:52:37.186510 2014] [authz_core:debug] [pid 17519:tid 139805499234048] mod_authz_core.c(802): [client 127.0.0.1:38935] AH01626: authorization result of Require all granted: granted, referer: http://127.0.0.1:38082/
[Mon Dec 22 19:52:37.186549 2014] [authz_core:debug] [pid 17519:tid 139805499234048] mod_authz_core.c(802): [client 127.0.0.1:38935] AH01626: authorization result of <RequireAny>: granted, referer: http://127.0.0.1:38082/
[Mon Dec 22 19:52:37.187952 2014] [authz_core:debug] [pid 17524:tid 139805413340928] mod_authz_core.c(802): [client 127.0.0.1:38934] AH01626: authorization result of Require all granted: granted, referer: http://127.0.0.1:38082/
[Mon Dec 22 19:52:37.187977 2014] [authz_core:debug] [pid 17524:tid 139805413340928] mod_authz_core.c(802): [client 127.0.0.1:38934] AH01626: authorization result of <RequireAny>: granted, referer: http://127.0.0.1:38082/
[Mon Dec 22 19:52:37.189887 2014] [authz_core:debug] [pid 17524:tid 139805404948224] mod_authz_core.c(802): [client 127.0.0.1:38934] AH01626: authorization result of Require all granted: granted, referer: http://127.0.0.1:38082/
[Mon Dec 22 19:52:37.189901 2014] [authz_core:debug] [pid 17524:tid 139805404948224] mod_authz_core.c(802): [client 127.0.0.1:38934] AH01626: authorization result of <RequireAny>: granted, referer: http://127.0.0.1:38082/
[Mon Dec 22 19:52:37.191484 2014] [authz_core:debug] [pid 17519:tid 139805490841344] mod_authz_core.c(802): [client 127.0.0.1:38935] AH01626: authorization result of Require all granted: granted, referer: http://127.0.0.1:38082/
[Mon Dec 22 19:52:37.191502 2014] [authz_core:debug] [pid 17519:tid 139805490841344] mod_authz_core.c(802): [client 127.0.0.1:38935] AH01626: authorization result of <RequireAny>: granted, referer: http://127.0.0.1:38082/
[Mon Dec 22 19:52:37.242167 2014] [authz_core:debug] [pid 17524:tid 139805396555520] mod_authz_core.c(802): [client 127.0.0.1:38934] AH01626: authorization result of Require all granted: granted, referer: http://127.0.0.1:38082/
[Mon Dec 22 19:52:37.242193 2014] [authz_core:debug] [pid 17524:tid 139805396555520] mod_authz_core.c(802): [client 127.0.0.1:38934] AH01626: authorization result of <RequireAny>: granted, referer: http://127.0.0.1:38082/

access-log 访问日志

127.0.0.1 - - [22/Dec/2014:19:52:37 +0800] "GET / HTTP/1.1" 200 5339
127.0.0.1 - - [22/Dec/2014:19:52:37 +0800] "GET /css/bootstrap.min.css HTTP/1.1" 200 99548
127.0.0.1 - - [22/Dec/2014:19:52:37 +0800] "GET /css/style.css HTTP/1.1" 200 1042
127.0.0.1 - - [22/Dec/2014:19:52:37 +0800] "GET /css/bootstrap-theme.min.css HTTP/1.1" 200 13135
127.0.0.1 - - [22/Dec/2014:19:52:37 +0800] "GET /js/jquery.min.js HTTP/1.1" 200 93107
127.0.0.1 - - [22/Dec/2014:19:52:37 +0800] "GET /js/bootstrap.min.js HTTP/1.1" 200 27822
127.0.0.1 - - [22/Dec/2014:19:52:37 +0800] "GET /img/zf2-logo.png HTTP/1.1" 200 738

apache Logs when access from nginx apache从nginx访问时记录

access-log 访问日志

127.0.0.1 - - [22/Dec/2014:20:29:08 +0800] "GET /index.php HTTP/1.0" 404 2345

error-log 错误日志

[Mon Dec 22 20:29:08.387773 2014] [authz_core:debug] [pid 20897:tid 140375947659008] mod_authz_core.c(802): [client 127.0.0.1:39363] AH01626: authorization result of Require all granted: granted
[Mon Dec 22 20:29:08.387818 2014] [authz_core:debug] [pid 20897:tid 140375947659008] mod_authz_core.c(802): [client 127.0.0.1:39363] AH01626: authorization result of <RequireAny>: granted

ngnix access log. ngnix访问日志。 no error log 没有错误日志

127.0.0.1 - - [22/Dec/2014:20:29:08 +0800] "GET / HTTP/1.1" 404 2345 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0" "-"
127.0.0.1 - - [22/Dec/2014:20:29:08 +0800] "GET /css/bootstrap.min.css HTTP/1.1" 200 99548 "http://127.0.0.1:8082/" "Mozilla/5.0 (X11; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0" "-"
127.0.0.1 - - [22/Dec/2014:20:29:08 +0800] "GET /css/bootstrap-theme.min.css HTTP/1.1" 200 13135 "http://127.0.0.1:8082/" "Mozilla/5.0 (X11; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0" "-"
127.0.0.1 - - [22/Dec/2014:20:29:08 +0800] "GET /css/style.css HTTP/1.1" 200 1042 "http://127.0.0.1:8082/" "Mozilla/5.0 (X11; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0" "-"
127.0.0.1 - - [22/Dec/2014:20:29:08 +0800] "GET /js/jquery.min.js HTTP/1.1" 200 93107 "http://127.0.0.1:8082/" "Mozilla/5.0 (X11; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0" "-"
127.0.0.1 - - [22/Dec/2014:20:29:08 +0800] "GET /js/bootstrap.min.js HTTP/1.1" 200 27822 "http://127.0.0.1:8082/" "Mozilla/5.0 (X11; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0" "-"
127.0.0.1 - - [22/Dec/2014:20:29:08 +0800] "GET /img/zf2-logo.png HTTP/1.1" 200 738 "http://127.0.0.1:8082/" "Mozilla/5.0 (X11; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0" "-"

I think you are missing some headers. 我认为您缺少一些标题。 try adding something like this: 尝试添加如下内容:

location ~ \.php$ {
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
    proxy_http_version 1.1;
    proxy_pass http://127.0.0.1:38082;
}

-- Update -- -更新-

I noticed the difference between the log is the http version. 我注意到日志之间的区别是http版本。 I added a rule to force ver 1.1 (check up) - Hope it works 我添加了强制1.1版(检查)的规则-希望它能起作用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM