子文件夹中带有Angular 和codeigniter应用程序的Nginx

3duebb1j  于 2022-12-07  发布在  Angular
关注(0)|答案(2)|浏览(133)

我正在尝试做一个网站,后端使用codeigniter,前端使用angularjs。后端我使用nginx作为服务器。目前我在正确配置nginx时遇到了问题。我想实现的是将codeigniter和angularjs应用程序放在不同的文件夹中。我想访问的是如下所示

  • 来自我的网站的代码点火器
  • 来自my_website.com的Angular

至于文件夹,我想把它们放在:

  • 密码触发器:文件
  • Angular :/var/www/html/angular

到目前为止,我已经设法让它在同一个文件夹中工作。所以现在我在/var/www/html中有codeigniter,而angular文件夹在同一个目录中。这样我就可以从my_website.com/访问codeigniter,而从my_website.com/app访问angular,这不是我想要的。
我尝试了多个不同的nginx /etc/nginx/sites-available/default文件的设置,但每次都遇到一些问题。最严重的是我把它们放在单独的文件夹中,但codeigniter只对default_controller有效,我无法访问任何其他文件。这是当前的工作配置。

server {
    listen 80;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/html;

    server_name localhost;
    index index.php index.htm index.html;

    location /app/ {
        root /var/www/html/angular; 
        try_files $uri/ $uri index.html =404;
    }

    location / {
        try_files $uri $uri/ /index.php;
        #index index.html;
    }

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
        include fastcgi_params;
    }
}

这是一个简单的配置,我尝试从演示子文件夹运行codeigniter,

server {
        listen       80;
        server_name  localhost;
        root   /var/www/html;
        autoindex on;
        index index.php;

        location / {

            #try_files $uri $uri/ /index.php;
                try_files $uri $uri/ /index.php$request_uri;
            location = /demo/index.php {
                try_files $uri $uri/ /index.php$request_uri;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

                fastcgi_param  SCRIPT_FILENAME /var/www/html/demo$fastcgi_script_name;
                include        fastcgi_params;
            }
        }

        location ~ \.php$ {
            return 444;
        }

}

在这里,my_website.com/demo/index.php工作正常,但my_website.com/demo/index.php/欢迎显示 *500内部服务器错误 *
我希望我说得很清楚。我试过网上找到的很多不同的配置,但是我总是遇到一些麻烦。你们中的任何一个能提出一些简单的解决这个问题的方法吗?
谢谢马特乌斯

eqfvzcg8

eqfvzcg81#

我终于设法让它工作的方式我想要的。我已经使用这个解决方案link,使它与codeigniter在子目录,这是主要的问题。这里是我的配置:

server {
    listen       80;
    server_name  localhost;
    root   /var/www/html;
    autoindex on;
    index index.html;

    location / {
        root /var/www/html/angular; 
        try_files $uri/ $uri index.html =404;
    }

    location /api/ {
            alias  /var/www/html/api/;
            try_files $uri $uri/ /api/index.php;

            location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_index   index.php;
                fastcgi_pass    unix:/var/run/php/php7.0-fpm.sock;
                include /etc/nginx/fastcgi_params;
                fastcgi_param   SCRIPT_FILENAME $request_filename;
        }
    }

    location ~ \.php$ {
        return 444;
    }
}

感谢@FrédéricHenri建议使用/var/log/nginx/*.log下的日志文件,这有助于跟踪nginx重定向请求的方式。另外,我遇到的是网页浏览器缓存网站(我认为这是正在发生的事情),所以当我对配置文件做一些修改时,给了我错误的结果。

rdlzhqv9

rdlzhqv92#

如果你已经安装了~ .php和其他东西。那么只需要添加

location /ci-project {
             try_files $uri $uri/ /ci-project/index.php;
        }

在您的服务器{Nginx配置}对象中

相关问题