简体   繁体   English

NGINX + Apache2 + codeigniter-子路径不起作用

[英]NGINX + Apache2 + codeigniter - Subpath not working

I currently have 2 PHP applications up and running on my DigitalOcean's Ubuntu server. 我目前在DigitalOcean的Ubuntu服务器上启动并运行了2个PHP应用程序。 There is a third one as well, but it's not working. 还有第三个,但它不起作用。 All three PHP projects are configured to run on different ports. 所有这三个PHP项目都配置为在不同的端口上运行。 Meanwhile, using NGINX server I have configured a reverse proxy. 同时,使用NGINX服务器,我已经配置了反向代理。 The configuration is as given below. 配置如下。

/etc/nginx/nginix.conf /etc/nginx/nginix.conf

server {
        listen          80;
        server_name     IP;
        location / {
              #Assinged to a python project
        }
        location /php_project_1 {
            proxy_pass http://IP:5002;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header HOST $http_host;
        }

        location /php_project_2 {
            proxy_pass http://IP:5003;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header HOST $http_host;
        }
        location /php_project_3 {
            proxy_pass http://IP:5004;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header HOST $http_host;

        }
    }

I have also created 3 configuration files in /etc/apache2/sites-available . 我还在/ etc / apache2 / sites-available中创建了3个配置文件。

PROBLEM 问题

php_project_1 and php_project_2 are developed using core PHP and they work fine. php_project_1和php_project_2是使用核心PHP开发的,它们可以正常工作。

php_project_3 is developed using codeigniter . php_project_3是使用codeigniter开发的。 and that is the project which is causing me problems. 那是导致我麻烦的项目。 Inside this project, under /application/config/config.php I have modified $config['base_url'] and entered the values as http://IP/php_project_3 . 在这个项目中,在/application/config/config.php下,我修改了$config['base_url']并将值输入为http:// IP / php_project_3

However, when I hit the URL http://IP/php_project_3 , I get a blank page. 但是,当我点击URL http://IP/php_project_3 ,我得到了一个空白页。 I also checked /var/logs/apache2 and /var/logs/nginx , however, the error.log file does not show any messages corresponding to my request. 我还检查了/ var / logs / apache2/ var / logs / nginx ,但是error.log文件没有显示与我的请求相对应的任何消息。

Meanwhile, I can successfully run the other 2 applications using http://IP/php_project_1 and http://IP/php_project_2 同时,我可以使用http://IP/php_project_1http://IP/php_project_2成功运行其他2个应用程序

I don't know how to troubleshoot this issue. 我不知道如何解决此问题。

The value for $config['base_url'] should end in a slash, so try $config['base_url']应以斜杠结尾,因此请尝试

$config['base_url'] = 'http://IP/php_project_3/';

If the above still produces a blank and there are no errors to be found in any log files at /application/logs/ then you might have a BOM on one of your script files. 如果以上仍然产生空白,并且在/application/logs/任何日志文件中都没有发现错误,则您的脚本文件之一上可能有BOM。 I've run into them at the very beginning of the script before the opening <?php . 在打开<?php之前,我在脚本的开头就遇到了它们。 Start with the controller. 从控制器开始。 Delete that opening line, then retype it - test, repeat on any "view" files the controller uses until you find the offender. 删除该开头的行,然后重新输入-测试,对控制器使用的所有“查看”文件重复,直到找到违规者。

You can see if the proxy is being delivered to the correct directory by temporarily replacing CodeIgniter's index.php with another file of the same name but with a simple text output, ie 您可以通过将CodeIgniter的index.php临时替换为另一个具有相同名称但具有简单文本输出的文件来查看代理是否传递到正确的目录,即

<?php
echo "Hello World"; 

Obviously, if you see the text the problem lies outside of a server config issue. 显然,如果看到文本,则问题出在服务器配置问题之外。

I ran into a similar issue when running codeigniter behind trafik. 在trafik后面运行codeigniter时遇到了类似的问题。 After pulling all of my hair out I realized that it was because the IP of the traefik instance had to be included in the auth.conf file. 拔掉所有头发后,我意识到这是因为traefik实例的IP必须包含在auth.conf文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM