如何在nginx-bitnami-CI中设置子目录?

我正在使用Nginx bitnami codeigniter服务器。

在根文件夹中已存在现有codeigniter项目的情况下,现在有必要将新应用程序添加到子文件夹中。 在apache中,只需创建一个子文件夹并将codeigniter复制到其中,但在nginx中,它继续作为root应用程序连接,将子文件夹视为控制器,并发生404错误。 我应该如何设置?

这是我的Bitnami配置文件。

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; 
    }

谢谢。

kubikiri 回答:如何在nginx-bitnami-CI中设置子目录?

您是否将应用程序部署在/opt/bitnami/nginx/html目录(NGINX的根目录)中?如果使用其他路径,则需要配置NGINX来提供这些文件

您可以按照以下步骤从头开始部署自定义PHP应用程序。这些步骤假定您的应用程序将位于/ opt / bitnami / apps / myapp /目录中:

  • 运行以下命令来创建目录并分配必要的权限:
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/
  • 创建和编辑/opt/bitnami/apps/myapp/conf/nginx-prefix.conf文件,并将以下行添加到其中:
location /myapp {
  alias "/opt/bitnami/apps/myapp/htdocs/";
  include "/opt/bitnami/apps/myapp/conf/nginx-app.conf";
}
  • 创建和编辑/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;
}
  • 在/opt/bitnami/nginx/conf/bitnami/bitnami-apps-prefix.conf文件的末尾添加以下行:
include "/opt/bitnami/apps/myapp/conf/nginx-prefix.conf";
  • 重新启动NGINX服务器:
sudo /opt/bitnami/ctlscript.sh restart nginx

您可以在我们的文档中找到更多信息:https://docs.bitnami.com/general/infrastructure/nginx/administration/create-custom-application-php/

本文链接:https://www.f2er.com/3167617.html

大家都在问