在WT-NMP上设置nginx配置

时间:2015-10-27 22:30:11

标签: php nginx

我在nginx.conf中添加了以下配置:

server {
    server_name domain.vhost;
    root C:/WT-NMP/WWW/domain.vhost/web;

    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;
    }
    # DEV
    # This rule should only be placed on your development environment
    # In production, don't include this and don't deploy app_dev.php or config.php
    location ~ ^/(app_dev|config)\.php(/|$) {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include nginx.fastcgi.conf;
        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
    }
    # PROD
    location ~ ^/app\.php(/|$) {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include nginx.fastcgi.conf;
        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        # Prevents URIs that include the front controller. This will 404:
        # http://domain.tld/app.php/some-path
        # Remove the internal directive to allow URIs like this
        #internal;
    }

    error_log C:/WT-NMP/log/domain.vhost.error.log;
    access_log C:/WT-NMP/log/domain.vhost.access.log;
}

问题在于它不起作用。它在我的Ubuntu服务器上。它不在我的Windows WT-NMP nginx本地机器上。没有显示日志,我可以访问的唯一URL是:

domain.vhost/domain.vhost/web/app_dev.php/, 当我进入domain.vhost/时 我得到服务器上的文件列表可供选择。

怎么了?

1 个答案:

答案 0 :(得分:0)

您从Linux服务器复制/粘贴指令而不了解它们。用于Windows的WT-NMP服务器堆栈在您创建新项目时生成Nginx配置文件。首先创建一个新项目并仔细修改它的配置文件conf\domains.d\myProject.conf,并使用其他机器的指令。

WT-NMP: How to create a new Project

由于您似乎使用自定义子目录作为公共文件,请阅读

WT-NMP: How to change the root directory of a project

此外,NGINX Documentation应该有所帮助..

提示:不要从Linux服务器复制fastcgi_passfastcgi_split_path_info指令