【问题标题】:wnmp nginx configuration for Zend Framework 1.12 (Windows, nginx, mariadb, php 7)Zend Framework 1.12 的 wnmp nginx 配置(Windows、nginx、mariadb、php 7)
【发布时间】:2016-04-22 15:11:47
【问题描述】:

我有一个基于 zend 框架 1.12 的站点,其 .htaccess 内容如下

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]

我在windows 7专业版上安装了wnmp来测试windows、nginx、mariadb、php7

本地主机上的主页效果很好。 PHP 7 和 mariaDB 运行良好,并在主页 localhost (http://localhost) 上显示数据和图像

我也尝试了很多东西,stackoverflow的例子Apache rewrite rule to NGINX for HHVM

我的主机网址直截了当 喜欢 http://localhost/conference/sessions/date/2015-04/12/page/1 会议 - 控制器 会议 - 行动 请求参数日期和具有相应值的页面

这是我的 nginx.conf 中的内容

worker_processes  1;

error_log  logs/error.log;
pid        logs/nginx.pid;

events {
    # Max value 16384
    worker_connections  8192;
    # Accept multiple connections
    multi_accept on;
}

# Settings that affect all server blocks
http {
    include php_processes.conf;
    include       mime.types;
    default_type  application/octet-stream;

    access_log  logs/access.log;

    sendfile on;

    keepalive_timeout  65;
    ssl_session_timeout 10m;
    ssl_protocols TLSv1.2 TLSv1.1 TLSv1 SSLv3;
    ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AES:RSA+3DES:!ADH:!AECDH:!MD5:!DSS; 
    ssl_prefer_server_ciphers on;
    gzip  on;
    # http server

# Begin HTTP Server
server {
    listen 80; # IPv4
    server_name localhost;

    ## Parametrization using hostname of access and log filenames.
    access_log logs/localhost_access.log;
    error_log logs/localhost_error.log;

    ## Root and index files.
    root html;
    index  index.php index.html index.htm;

    ## If no favicon exists return a 204 (no content error).
    location = /favicon.ico {
        try_files $uri =204;
        log_not_found off;
        access_log off;
    }

    ## Don't log robots.txt requests.
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
    ## Try the requested URI as files before handling it to PHP.
    location / {

        ## Regular PHP processing.
        location ~ \.php$ {
            try_files  $uri =404;
            fastcgi_pass   php_processes;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        ## Static files
        location ~* \.(?:css|gif|htc|ico|js|jpe?g|png|swf)$ {
            expires max;
            log_not_found off;
            ## No need to bleed constant updates. Send the all shebang in one
            ## fell swoop.
            tcp_nodelay off;
            ## Set the OS file cache.
            open_file_cache max=1000 inactive=120s;
            open_file_cache_valid 45s;
            open_file_cache_min_uses 2;
            open_file_cache_errors off;
        }

        ## Keep a tab on the 'big' static files.
        location ~* ^.+\.(?:ogg|pdf|pptx?)$ {
            expires 30d;
            ## No need to bleed constant updates. Send the all shebang in one
            ## fell swoop.
            tcp_nodelay off;
        }
        } # / location

} 
# End HTTP Server

# Begin HTTPS Server
server {
    listen 443 http2 ssl;
    server_name localhost;
    ssl_certificate      cert.pem;
    ssl_certificate_key  key.pem;
    ssl_session_cache   shared:SSL:10m;
    ssl_session_timeout 10m;

    ## Parametrization using hostname of access and log filenames.
    access_log logs/localhost_access.log;
    error_log logs/localhost_error.log;

    ## Root and index files.
    root html;
    index  index.php index.html index.htm;

    ## If no favicon exists return a 204 (no content error).
    location = /favicon.ico {
        try_files $uri =204;
        log_not_found off;
        access_log off;
    }

    ## Don't log robots.txt requests.
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
    ## Try the requested URI as files before handling it to PHP.
    location / {

        ## Regular PHP processing.
        location ~ \.php$ {
            try_files  $uri =404;
            fastcgi_pass   php_processes;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        ## Static files are served directly.
        location ~* \.(?:css|gif|htc|ico|js|jpe?g|png|swf)$ {
            expires max;
            log_not_found off;
            ## No need to bleed constant updates. Send the all shebang in one
            ## fell swoop.
            tcp_nodelay off;
            ## Set the OS file cache.
            open_file_cache max=1000 inactive=120s;
            open_file_cache_valid 45s;
            open_file_cache_min_uses 2;
            open_file_cache_errors off;
        }

        ## Keep a tab on the 'big' static files.
        location ~* ^.+\.(?:ogg|pdf|pptx?)$ {
            expires 30d;
            ## No need to bleed constant updates. Send the all shebang in one
            ## fell swoop.
            tcp_nodelay off;
        }
        } # / location
} # End HTTPS Server
}

请帮我解决这个问题;我是 nginx 新手。

【问题讨论】:

    标签: windows zend-framework nginx


    【解决方案1】:

    尝试在服务器配置中添加 server {...} 重定向到 index.php 以获取未找到的资源

    try_files $uri @missing;
    location @missing {
        rewrite .* /index.php;
    }
    

    root ...; 应该指向包含index.php 的公共目录

    【讨论】:

    • 第41行我用过root = html,html是安装wnmp的公共目录。这是在位置 c:\wnmp\html @MaxP
    • 谢谢@MaxP。 index.php 位于根目录。终于让它工作了。我在} # / location 结束之前添加了try_files $uri $uri/ @missing;,然后在之外添加了location @missing { rewrite (.*) /index.php; }。之后遇到了许多错误,因为需要为 PHP7 修复代码。我得到状态码 502 bad gateway。我添加了fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; 来修复它们。我想了解它们的含义以及我们如何确定缓冲区 abd 缓冲区大小。当我们有很多用户访问该网站时,这对于上线至关重要。
    猜你喜欢
    • 1970-01-01
    • 2014-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-02
    • 2014-08-31
    • 2017-02-11
    • 1970-01-01
    相关资源
    最近更新 更多