Reputation: 732
I'm trying to set up nginx configuration file for multi-project php located in different folders. 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.
In nginx debug log, I see the following information. 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. I'm not devops, so I don't know how to solve this.
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 [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"
Thanks in advance.
Upvotes: 0
Views: 863
Reputation: 746
first if server_name , your localhost , set localhost
second set your /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
Upvotes: 1