我正在尝试在 phplist 中安装 codeigniter,并且一切在 apache 中运行良好。
但是当上传到使用 nginx 的实时服务器时,出现 404 错误。
我知道这一定是 mod_rewrite 的问题,并尝试用谷歌搜索配置,但没有运气。
请帮助修复 nginx 的配置,其中 codeigniter 位于 phplist 内
提前致谢
注意:Services 是 codeigniter 文件的子目录名称
这是我的配置
server {
listen 443 ssl http2;
#listen [::]:443 ssl;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
server_name _;
root /var/www/domain.domain/lists;
index index.php index.html index.htm;
location ~ [^/]\.php(/|$) {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_read_timeout 1200;
proxy_connect_timeout 1200;
proxy_send_timeout 1200;
proxy_read_timeout 1200;
send_timeout 1200;
}
location ~ /.ht {
deny all;
}
location ~ /.well-known {
allow all;
}
location /phpmyadmin {
index index.php;
}
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}
// ADDING this conf for codeigniter inside phplist but no luck
location /services/ {
alias /var/www/domain.domain/lists/services/;
try_files $uri $uri/ /services/index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass backend;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
}
server {
listen 80;
#listen [::]:80 ipv6only=on;
server_name _;
return 302 https://$server_name$request_uri;
}
我收到了这个错误
sudo nginx -t
nginx: [emerg] no port in upstream "backend" in /etc/nginx/sites-enabled/your.conf:52
nginx: configuration file /etc/nginx/nginx.conf test failed
怎么解决!!
问题已解决,触发错误的原因是 fastcgi_pass 被设置为“backend”,而在我的情况下应该设置为“fpm-sock”位置。
这是我的最终配置,codeigniter 运行良好。
server {
listen 443 ssl http2;
#listen [::]:443 ssl;
include snippets/self-signed.conf;
include snippets/ssl-params.conf;
server_name _;
root /var/www/domain.domain/lists;
index index.php index.html index.htm;
location ~ [^/]\.php(/|$) {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_read_timeout 1200;
proxy_connect_timeout 1200;
proxy_send_timeout 1200;
proxy_read_timeout 1200;
send_timeout 1200;
}
location ~ /.ht {
deny all;
}
location ~ /.well-known {
allow all;
}
location /phpmyadmin {
index index.php;
}
if (!-e $request_filename) {
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}
location /services/ {
alias /var/www/domain.domain/lists/services/;
try_files $uri $uri/ /services/index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
}
server {
listen 80;
#listen [::]:80 ipv6only=on;
server_name _;
return 302 https://$server_name$request_uri;
}