首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在nginx-bitnami-CI中设置子目录?

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

Stack Overflow用户
提问于 2019-11-04 18:13:50
回答 1查看 274关注 0票数 0

我使用的是Nginx bitnami codeigniter服务器。

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

这是我的Bitnami配置文件。

代码语言:javascript
复制
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。

代码语言:javascript
复制
if (!-e $request_filename ) { 
          rewrite ^(.*)$ /index.php last; 
    }

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2019-11-08 19:44:29

你把你的应用部署到/opt/bitnami/nginx/html目录(NGINX的根目录)了吗?如果您使用不同的路径,则需要配置NGINX来提供这些文件

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

  • 运行以下命令以创建目录并分配必要的权限:

代码语言:javascript
复制
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文件,并向其中添加以下行:

代码语言:javascript
复制
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文件,并向其中添加以下内容。这是应用程序的主配置文件,因此根据应用程序的requirements.

进一步修改它

代码语言:javascript
复制
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文件的末尾添加以下行:

代码语言:javascript
复制
include "/opt/bitnami/apps/myapp/conf/nginx-prefix.conf";

  • 重启NGINX服务器:

代码语言:javascript
复制
sudo /opt/bitnami/ctlscript.sh restart nginx

访问http://SERVER-IP/myapp.上的

  • 应用程序

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58691253

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档