【问题标题】:Nginx configuration for multi-project folders多项目文件夹的 Nginx 配置
【发布时间】:2020-01-19 21:28:24
【问题描述】:

我正在尝试为位于不同文件夹中的多项目 php 设置 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;
    }
}

我打开浏览器并尝试连接到 /ardu-component/ 并从 nginx 收到 File not found 错误。

在 nginx 调试日志中,我看到以下信息。它似乎开始很好地解决位置和东西,但它最终以/usr/share/nginx... 结束,我没有在 conf.xml 中配置它。我不是devops,所以我不知道如何解决这个问题。

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 [调试] 2720#2720: *4 http 脚本副本: "/index.php" 2019/09/18 23:14:21 [调试] 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 [调试] 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 [debug] 2720#2720: *4 fastcgi param: "HTTPS: off"

提前致谢。

【问题讨论】:

标签: php nginx


【解决方案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;

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2017-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 2017-05-28
    相关资源
    最近更新 更多