我们已经设置了2个CodeIgniter应用程序,它们在自己的目录上有自己完整的代码库,如本例所示。另外,我们也有wordpress博客在同一个public_html目录。
public_html/HOME_APP
public_html/admin_tool/ADMIN_TOOL_CODES
public_html/blog/WORDPRESS_CODES
HOME_APP
代码(CodeIgniter)和我们的WORDPRESS
工作良好。但是admin_tool
(CodeIgniter)不起作用。我们只能访问http://example.com/admin_tool/index.php
,但不能访问任何内部控制器页面。当访问其显示404
错误页面时。看起来路由是通过APP1
nginx规则如下:如果有人能帮助我们解决admin_tool
的问题,我将不胜感激。
server{
listen 80;
root /home/ubuntu/websites/example.com/public_html;
index index.html index.htm index.php;
server_name example.com;
access_log /home/ubuntu/websites/example.com/logs/access.log;
error_log /home/ubuntu/websites/example.com/logs/error.log error;
location ~* .(ico|css|js|gif|jpe?g|png)(?[0-9]+)?$ {
expires max;
log_not_found off;
}
location / {
index index.php;
# Check if a file or directory index file exists, else route it to index.php.
try_files $uri $uri/ /index.php;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ^~/admin_tool/ {
root /home/ubuntu/websites/example.com/public_html/admin_tool;
index index.php;
try_files $uri $uri/ /index.php$args;
}
}
server {
listen 443 ssl;
server_name example.com *.example.com;
return 301 http://$server_name$request_uri;
}
下面的操作应该对您的所有安装都有效:
# We define the index directory at the outermost level and therefore
# only once for all servers. Also note that we use the PHP file first
# because all main directories are handled by PHP scripts and this will
# give us best performance.
index index.php index.html index.htm;
server {
access_log /home/ubuntu/websites/example.com/logs/access.log;
error_log /home/ubuntu/websites/example.com/logs/error.log error;
# 80 is default!
#listen 80;
root /home/ubuntu/websites/example.com/public_html;
server_name example.com;
location / {
# Don't allow access to the logs directory.
location ~* ^/logs {
return 404;
}
# Don't allow access to PHP files.
location ~* .php$ {
return 404;
}
# Handle static files.
location ~* .(ico|css|js|gif|jpe?g|png)(?[0-9]+)?$ {
expires max;
log_not_found off;
}
# Directly return if the requested URI is a real file.
try_files $uri $uri/ index.php =404;
}
# Codeigniter and WordPress will always handle everything with their
# index.php script, therefore we only need to catch that case.
location = /index.php {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 443 ssl;
server_name example.com *.example.com;
return 301 http://$server_name$request_uri;
}
当我在子文件夹(仪表板)中使用codeigniter时,我遇到了同样的问题。所有非wordpress的请求都不会被接受,而是留在wordpress主页上。我修复了我的问题,在我的配置文件/etc/nginx/sites-available/{my-site-name}
location /dashboard {
try_files $uri $uri/ /dashboard/index.php;
}
location /index.php {
fastcgi_pass unix:/usr/sbin/php5-fpm;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}