简体   繁体   English

Nginx 配置多项目文件夹

[英]Nginx configuration for multi-project folders

I'm trying to set up nginx configuration file for multi-project php located in different folders.我正在尝试为位于不同文件夹中的多项目 php 设置 nginx 配置文件。 I have the following configuration file in my production server.我的生产服务器中有以下配置文件。

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;
    }
}

I open my browser and I tried to connect to /ardu-component/ and I get File not found error from nginx.我打开浏览器并尝试连接到 /ardu-component/ 并从 nginx 收到File not found错误。

In nginx debug log, I see the following information.在 nginx 调试日志中,我看到以下信息。 It seems to start well resolving location and stuff, but it ends up in /usr/share/nginx... and I did not configure that in conf.它似乎开始很好地解决位置和东西,但它最终在/usr/share/nginx...我没有在 conf.xml 中配置它。 I'm not devops, so I don't know how to solve this.我不是devops,所以我不知道如何解决这个问题。

2019/09/18 23:14:21 [debug] 2720#2720: *4 http script var: "/ardu-component/" 2019/09/18 23:14:21 [debug] 2720#2720: *4 trying to use file: "/ardu-component/" "/srv/www/ardu-component/ardu-component/" 2019/09/18 23:14:21 [debug] 2720#2720: *4 http script copy: "/index.php" 2019/09/18 23:14:21 [debug] 2720#2720: *4 http script var: "" 2019/09/18 23:14:21 [debug] 2720#2720: *4 trying to use file: "/index.php" "/srv/www/ardu-component/index.php" 2019/09/18 23:14:21 [debug] 2720#2720: *4 internal redirect: "/index.php?" 2019/09/18 23:14:21 [调试] 2720#2720: *4 http 脚本变量:“/ardu-component/” 2019/09/18 23:14:21 [调试] 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 [调试] 2720#2720: *4 http 脚本变量: "" 2019/09/18 23:14:21 [调试] 2720#2720: *4 尝试使用文件:“/index.php”“/srv/www/ardu-component/index.php”2019/09/18 23:14:21 [debug] 2720#2720:*4 内部重定向:“/index.php” php?” 2019/09/18 23:14:21 [debug] 2720#2720: *4 rewrite phase: 1... 2019/09/18 23:14:21 [debug] 2720#2720: *4 http script var: "/usr/share/nginx/html" 2019/09/18 23:14:21 [debug] 2720#2720: *4 http script var: "/index.php" 2019/09/18 23:14:21 [debug] 2720#2720: *4 fastcgi param: "SCRIPT_FILENAME: /usr/share/nginx/html/index.php" 2019/09/18 23:14:21 [debug] 2720#2720: *4 http script copy: "HTTPS" 2019/09/18 23:14:21 [debug] 2720#2720: *4 http script copy: "off" 2019/09/18 23:14:21 [debug] 2720#2720: *4 fastcgi param: "HTTPS: off" 2019/09/18 23:14:21 [调试] 2720#2720:*4 重写阶段:1 ... 2019/09/18 23:14:21 [调试] 2720#2720:*4 http 脚本变量:“ /usr/share/nginx/html" 2019/09/18 23:14:21 [调试] 2720#2720: *4 http 脚本变量:"/index.php" 2019/09/18 23:14:21 [调试] 2720#2720: *4 fastcgi 参数: "SCRIPT_FILENAME: /usr/share/nginx/html/index.php" 2019/09/18 23:14:21 [调试] 2720#2720: *4 http 脚本副本:" HTTPS” 2019/09/18 23:14:21 [调试] 2720#2720: *4 http 脚本副本:“关闭” 2019/09/18 23:14:21 [调试] 2720#2720: *4 fastcgi 参数: “HTTPS:关闭”

Thanks in advance.提前致谢。

first if server_name, your localhost, set localhost首先如果 server_name,你的本地主机,设置本地主机

second set your /srv/www第二个设置你的 /srv/www

code代码

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;
            }}  

if that not work, try如果这不起作用,请尝试

update更新

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

to

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

hoping that help you希望对你有帮助

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

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