gpt4 book ai didi

php - Codeigniter 的 nginx 重写规则无法正常工作

转载 作者:可可西里 更新时间:2023-11-01 13:31:23 25 4
gpt4 key购买 nike

我第一次尝试在 MAMP 中使用 nginx 服务器而不是 Codeigniter 的 apache 服务器。我将我的 apache htaccess 重写规则转换为 nginx 重写规则。但它显示的是我文件中的 index.php 文件代码,而不是我的网站。这是我的 apache htaccess 规则,

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

这是我的nginx配置文件,

http {
include mime.types;
default_type text/html;
gzip on;
gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;

sendfile on;

server {
listen 80 default_server;

# MAMP DOCUMENT_ROOT !! Don't remove this line !!
root "C:/MAMP/htdocs/aia_inventory/";

access_log C:/MAMP/logs/nginx_access.log;

error_log C:/MAMP/logs/nginx_error.log;

index index.html index.htm index.php;
#autoindex on;
#server_name localhost;
location ~/ {
#root C:/MAMP/htdocs/aia_inventory/;
#index index.html index.php;
try_files $uri $uri/ /index.php/$request_uri;

if (!-e $request_filename){
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
}

location ~* ^/(assets|files|robots\.txt) { }

location ~* /MAMP(.*)$ {
root C:/MAMP/bin;
index index.php;

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9100;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

location ~* /phpMyAdmin(.*)$ {
root C:/MAMP/bin;
index index.php;

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9100;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

location ~* /phpLiteAdmin(.*)$ {
root C:/MAMP/bin;
index phpliteadmin.php index.php;

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9100;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

location ~* /SQLiteManager(.*)$ {
root C:/MAMP/bin;
index index.php;

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9100;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

#location /icons {
# alias /Applications/MAMP/Library/icons;
# autoindex on;
#}

#location /favicon.ico {
# alias /Applications/MAMP/bin/favicon.ico;
# # log_not_found off;
# # access_log off;
#}

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9100;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

#location ~ /\. {
# deny all;
#}

# location ~* \.(gif|jpg|png|pdf)$ {
# expires 30d;
# }

# location = /robots.txt {
# allow all;
# log_not_found off;
# access_log off;
# }

# location ~* \.(txt|log)$ {
# allow 127.0.0.1;
# deny all;
# }

# location ~ \..*/.*\.php$ {
# return 403;
# }

#location /nginx_status {
# stub_status on;
# access_log off;
# allow 127.0.0.1;
# deny all;
#}
}
}

我不明白我错过了什么。我的规则适用于 apache 服务器。但在 nginx 服务器上,它只显示 index.php 文件原始代码。提前致谢。

最佳答案

试试这个

location ~ / {
root C:/MAMP/htdocs/inventory/;
index index.html index.php;
try_files $uri $uri/ /index.php/$request_uri;

if (!-e $request_filename){
rewrite ^(.*)$ /index.php/$1 break;
}
}
location ~* ^/(assets|files|robots\.txt) { }

关于php - Codeigniter 的 nginx 重写规则无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51593556/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com