我在 nginx 网络服务器上安装了多个 php 框架(Cakephp 和 Opencart)。Cakephp 在根目录中运行良好。Opencart 位于我遇到错误的子目录中。这是我的 nginx 配置文件。
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name dev.test.com;
return 301 https://$server_name$request_uri;
root /var/www/html/app/webroot/;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
}
server {
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/dev.test.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/dev.test.com/privkey.pem; # managed by Certbot
root /var/www/html/app/webroot;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
include snippets/phpmyadmin.conf;
server_name dev.test.com;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_intercept_errors on;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
location /estore/ {
alias /var/www/html/estore;
index index.html index.htm index.php;
try_files $uri $uri/ @opencart;
}
location @opencart {
rewrite ^/(.+)$ /index.php?_route_=$1 last;
}
}
答案1
尝试这个:
location ^~ /estore {
root /var/www/html;
index index.php index.html index.htm;
try_files $uri $uri/ @opencart;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_intercept_errors on;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
}
location @opencart {
rewrite ^/(.+)$ /estore/index.php?_route_=$1 last;
}