Problems with NGINX and PHP

1

Hi, I'm working on a personal project, the subject is the following, the application itself is mounted in NodeJS by topics that I need to use Socket.io and the application connects with API REST in PHP CodeIgniter for comfort issues regarding the code, it is hosted on the same server, the subject is as follows:

At the moment I was able to make the API work since if I enter misitio.com/api/loquesea it executes it well, the issue is that when entering the site in the root misitio.com/ the site that is made in NodeJS with Angular it does not show me anything, since the server tries to parse it as if it were CodeIgniter returning a error 404 each time it loads a js .

For example, this is the code I have at this time. All this is mounted in NGINX :

server {
    listen 80;
    server_name misitio.com;
    root /home/misitio.com/;

    location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
            proxy_pass http://localhost:3000;
            proxy_redirect off;
    }

    if ($request_uri ~ ^api/index/?$){
            rewrite ^/(.*)api/index/?$ /$1 permanent;
    }

    if (!-d $request_filename){
            rewrite ^/(.+)/$ /$1 permanent;
    }

    if ($request_uri ~ ^api/system){
            rewrite ^/(.*)$ /api/index.php?/$1 last;
            break;
    }

    if (!-e $request_filename){
            rewrite ^/(.*)$ /index.php?/$1 last;
            break;
    }

    error_page 404 /index.php;

    location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /home/misitio.com/api$fastcgi_script_name;
            include fastcgi_params;
    }

    location ~ /\.ht{
            deny all;
    }
}
    
asked by leiteszeke 10.08.2016 в 22:11
source

1 answer

0

Well, the solution works in the following way, I have Nginx running on port 80 and Apache on 8080. I have the server configured in nginx, which is where it goes ... When I enter mysitio.com, I make a reverse proxy to misitio.com:3000 which is where I have running my application in NodeJS. When entering misitio.com/api I make a proxy to localhost: 8080 which is where Apache is running from that moment, it starts running the Apache VirtualHost that is what leads me to what I am asking, in this case, I would be looking the content of / var / www / api /.

Try to do it the other way around, Apache in Port 80 and NGINX in another, but I did not get results.

    server { 
          listen 80 default_server; 
          listen [::]:80 default_server;
          server_name misitio.com www.misitio.com;

          root /var/www;
          index index.php index.html index.htm;

          location ~ ^/(images/|img/|assets/|templates/|photos/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico) {
                   root /var/www/ygobattlecity/public;
                   access_log off;
                   expires max;
          }

          location / {
                   proxy_pass http://misitio.com:3000;
                   proxy_redirect off;
          }

          location /api {
                   proxy_pass http://localhost:8080;
                   include /etc/nginx/proxy_params;
          }

          location ~* \.(js|css|jpg|jpeg|gif|png|svg|ico|pdf|html|htm)$ {
                   expires      30d;
          }

          location ~* \.php$ {
                   proxy_pass http://127.0.0.1:8080;
                   include /etc/nginx/proxy_params;
          }
   }

  <VirtualHost *:8080>
           ServerAdmin webmaster@localhost 
           ServerName misitio.com 
           ServerAlias www.misitio.com 
           DocumentRoot /var/www

           ErrorLog ${APACHE_LOG_DIR}/error.log
           CustomLog ${APACHE_LOG_DIR}/access.log combined

           <Directory />
                   Options FollowSymLinks
                   AllowOverride None
           </Directory>

           <Directory /var/www/>
                   Options Indexes FollowSymLinks MultiViews
                   AllowOverride All
                   Order allow,deny
                   allow from all
          </Directory>
   </VirtualHost>
    
answered by 01.09.2016 / 14:15
source