多项目文件夹的Nginx配置

时间:2019-09-18 21:30:06

标签: php nginx

我正在尝试为位于不同文件夹中的多项目php设置nginx配置文件。我的生产服务器中有以下配置文件。

RESULT_TENSOR

我打开浏览器,并尝试连接到/ ardu-component /,我从nginx收到server { listen 80; error_log /LOGS/ardu_error.log debug; access_log /LOGS/ardu_access.log; set $applicationEnv "production"; location ~ /ardu-component/ { root /srv/www/ardu-component/; try_files $uri /index.php$is_args$args; } location ~ ^/index\.php(/|$) { # the ubuntu default fastcgi_pass 127.0.0.1:9000; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param APPLICATION_ENV $applicationEnv; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS off; } #return 404 for all php files as we do have a front controller location ~ \.php$ { return 404; } } server { listen 80; error_log /LOGS/ardu_error.log debug; access_log /LOGS/ardu_access.log; set $applicationEnv "production"; location ~ /ardu-component/ { root /srv/www/ardu-component/; try_files $uri /index.php$is_args$args; } location ~ ^/index\.php(/|$) { # the ubuntu default fastcgi_pass 127.0.0.1:9000; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param APPLICATION_ENV $applicationEnv; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS off; } #return 404 for all php files as we do have a front controller location ~ \.php$ { return 404; } } 错误。

在nginx调试日志中,我看到以下信息。它似乎可以很好地解析位置和内容,但最终以File not found结尾,我没有在conf中进行配置。我不是开发者,所以我不知道该怎么解决。

  

2019/09/18 23:14:21 [debug] 2720#2720:* 4 http脚本var:   “ / ardu-component /” 2019/09/18 23:14:21 [debug] 2720#2720:* 4试图   使用文件:“ / ardu-component /”“ / srv / www / ardu-component / ardu-component /”   2019/09/18 23:14:21 [debug] 2720#2720:* 4 http脚本副本:   “ /index.php” 2019/09/18 23:14:21 [debug] 2720#2720:* 4 http脚本   var:“” 2019/09/18 23:14:21 [debug] 2720#2720:* 4尝试使用文件:   “ /index.php”“ /srv/www/ardu-component/index.php” 2019/09/18 23:14:21   [调试] 2720#2720:* 4内部重定向:“ / index.php?” 2019/09/18   23:14:21 [debug] 2720#2720:* 4重写阶段:1   ...   2019/09/18 23:14:21 [debug] 2720#2720:* 4 http脚本var:   “ / usr / share / nginx / html” 2019/09/18 23:14:21 [调试] 2720#2720:* 4 http   脚本var:“ /index.php” 2019/09/18 23:14:21 [debug] 2720#2720:* 4   fastcgi参数:“ SCRIPT_FILENAME:/usr/share/nginx/html/index.php”   2019/09/18 23:14:21 [debug] 2720#2720:* 4 http脚本副本:“ HTTPS”   2019/09/18 23:14:21 [debug] 2720#2720:* 4 http脚本副本:“ off”   2019/09/18 23:14:21 [debug] 2720#2720:* 4 fastcgi param:“ HTTPS:off”

谢谢。

1 个答案:

答案 0 :(得分:1)

首先,如果server_name(您的本地主机)设置了本地主机

第二次设置/ srv / www

代码

server {  
     location ~ /\. { deny  all; }
    listen *:80 ;       
     server_name   localhost     ;
      root   /srv/www;


    location / {root   /srv/www/;




                    index  index.htm  index.html  index.php;
    }



   location ^~ /ardu-component {    
        try_files $uri /index.php$is_args$args;
    }


        location ~ ^/.+\.php {
              fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /home/lecad/public_html/$fastcgi_script_name;
                    fastcgi_param PATH_INFO $fastcgi_script_name;
    fastcgi_param PHP_ADMIN_VALUE "open_basedir=\"/srv/www/:/tmp:/usr/local/lib/php:\"
    include_path=\"/usr/lib/php:/usr/local/lib/php:/tmp:/srv/www/\"";
               include /etc/nginx/fastcgi_params;
            }}  

如果该方法无效,请尝试

更新

try_files $uri /index.php$is_args$args;

try_files /ardu-component/$uri /ardu-component/index.php$is_args$args;

希望对您有帮助