gpt4 book ai didi

codeigniter - nginx配置,避免codeigniter重写规则

转载 作者:行者123 更新时间:2023-12-04 03:12:20 28 4
gpt4 key购买 nike

这是 codeigniter 的 nginx 重写规则。
我们可以通过谷歌搜索轻松找到这一点。

server
{
server_name .example.com;

access_log /var/log/nginx/example.com.access.log;

root /var/www/example.com/html;

index index.php index.html index.htm;

# enforce www (exclude certain subdomains)
# if ($host !~* ^(www|subdomain))
# {
# rewrite ^/(.*)$ $scheme://www.$host/$1 permanent;
# }

# enforce NO www
if ($host ~* ^www\.(.*))
{
set $host_without_www $1;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}

# canonicalize codeigniter url end points
# if your default controller is something other than "welcome" you should change the following
if ($request_uri ~* ^(/welcome(/index)?|/index(.php)?)/?$)
{
rewrite ^(.*)$ / permanent;
}

# removes trailing "index" from all controllers
if ($request_uri ~* index/?$)
{
rewrite ^/(.*)/index/?$ /$1 permanent;
}

# removes trailing slashes (prevents SEO duplicate content issues)
if (!-d $request_filename)
{
rewrite ^/(.+)/$ /$1 permanent;
}

# removes access to "system" folder, also allows a "System.php" controller
if ($request_uri ~* ^/system)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}

# unless the request is for a valid file (image, js, css, etc.), send to bootstrap
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}

# catch all
error_page 404 /index.php;

# use fastcgi for all php files
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/example.com/html$fastcgi_script_name;
include fastcgi_params;
}

# deny access to apache .htaccess files
location ~ /\.ht
{
deny all;
}
}

我想在此服务器中添加普通的 php 项目。
项目的根目录是 /var/www/another/proj_new .

正如我所提到的,这个新项目不使用 codeigniter 框架。
这是正常的php文件项目。所以它不需要 Codeigniter 重写规则。

所以,我的问题是我可以通过网络访问新项目。

地址可能是这样的:
http://example.com/proj_new

该地址不应调用 codeigniter 的 proj_new Controller 。

我尝试添加此设置:
server
{
....
....
....

localhost /proj_new {
root /var/www/another/proj_new
index index.php
}

....
....
....
}

但是, http://example.com/proj_new制作 404 错误页面。

最佳答案

我建议从 Nginx 进行此配置

server {
server_name nginxcodeigniter.net;

root /var/www/codeigniter;
index index.html index.php;

# set expiration of assets to MAX for caching
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}

location / {
# Check if a file exists, or route it to index.php.
try_files $uri $uri/ /index.php;
}

location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}

在此之后,请确保您的 codeIgniter config.php 包含以下信息:
$config['base_url'] = "http://nginxcodeigniter.net/";
$config['index_page'] = "";
$config['uri_protocol'] = "REQUEST_URI";

来源: Nginx

关于codeigniter - nginx配置,避免codeigniter重写规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8182868/

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