Php 如何在nginx bitnami CI中设置子目录?
我正在使用Nginx bitnami codeigniter服务器 现有的codeigniter项目位于根文件夹中,现在需要向子文件夹添加新的应用程序。 在apache中,只需创建一个子文件夹并将codeigniter复制到其中,但在nginx中,它继续作为root应用程序连接,将子文件夹视为控制器,并发生404错误。 我应该如何设置它 这是我的Bitnami配置文件Php 如何在nginx bitnami CI中设置子目录?,php,codeigniter,nginx,bitnami,Php,Codeigniter,Nginx,Bitnami,我正在使用Nginx bitnami codeigniter服务器 现有的codeigniter项目位于根文件夹中,现在需要向子文件夹添加新的应用程序。 在apache中,只需创建一个子文件夹并将codeigniter复制到其中,但在nginx中,它继续作为root应用程序连接,将子文件夹视为控制器,并发生404错误。 我应该如何设置它 这是我的Bitnami配置文件 server { listen 80; server_name localhost;
server {
listen 80;
server_name localhost;
include "/opt/bitnami/nginx/conf/bitnami/phpfastcgi.conf";
include "/opt/bitnami/nginx/conf/bitnami/bitnami-apps-prefix.conf";
## Root and index files.
root /opt/bitnami/nginx/html;
index index.php index.html index.htm;
## If no favicon exists return a 204 (no content error).
location = /favicon.ico {
try_files $uri =204;
log_not_found off;
access_log off;
}
## Don't log robots.txt requests.
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
## Try the requested URI as files before handling it to PHP.
location / {
proxy_buffers 8 1024k;
proxy_buffer_size 1024k;
## Regular PHP processing.
location ~ \.php$ {
try_files $uri =404;
#fastcgi_pass php_processes;
fastcgi_pass unix:/opt/bitnami/php/var/run/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
## Static files
location ~* \.(?:css|gif|htc|ico|js|jpe?g|png|swf)$ {
expires max;
log_not_found off;
## No need to bleed constant updates. Send the all shebang in one
## fell swoop.
tcp_nodelay off;
## Set the OS file cache.
open_file_cache max=1000 inactive=120s;
open_file_cache_valid 45s;
open_file_cache_min_uses 2;
open_file_cache_errors off;
}
## Keep a tab on the 'big' static files.
location ~* ^.+\.(?:ogg|pdf|pptx?)$ {
expires 30d;
## No need to bleed constant updates. Send the all shebang in one
## fell swoop.
tcp_nodelay off;
}
} # / location
if (!-e $request_filename ) {
rewrite ^(.*)$ /index.php last;
}
}
这段代码将所有路径重定向到indx.php
if (!-e $request_filename ) {
rewrite ^(.*)$ /index.php last;
}
谢谢。您是否将应用程序部署在
/opt/bitnami/nginx/html
目录(nginx的根目录)中?如果使用了不同的路径,则需要配置NGINX以服务于这些文件
您可以按照以下步骤从头开始部署定制PHP应用程序。这些步骤假定您的应用程序将位于/opt/bitnami/apps/myapp/目录中:
- 运行以下命令以创建目录并分配必要的权限:
- 创建并编辑/opt/bitnami/apps/myapp/conf/nginx-prefix.conf文件,并添加以下行:
- 创建并编辑/opt/bitnami/apps/myapp/conf/nginx-app.conf文件,并将以下内容添加到其中。这是应用程序的主配置文件,因此请根据应用程序的要求对其进行进一步修改
- 在/opt/bitnami/nginx/conf/bitnami/bitnami-apps-prefix.conf文件末尾添加以下行:
- 重新启动NGINX服务器:
- 访问位于的应用程序
sudo mkdir /opt/bitnami/apps/myapp
sudo mkdir /opt/bitnami/apps/myapp/htdocs/
sudo mkdir /opt/bitnami/apps/myapp/conf
sudo chown -R bitnami:daemon /opt/bitnami/apps/myapp/htdocs/
sudo chmod -R g+w /opt/bitnami/apps/myapp/htdocs/
location /myapp {
alias "/opt/bitnami/apps/myapp/htdocs/";
include "/opt/bitnami/apps/myapp/conf/nginx-app.conf";
}
index index.php index.html index.htm;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_read_timeout 300;
fastcgi_pass unix:/opt/bitnami/php/var/run/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
include "/opt/bitnami/apps/myapp/conf/nginx-prefix.conf";
sudo /opt/bitnami/ctlscript.sh restart nginx