Nginx php reverse proxy problem

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Nginx php reverse proxy problem

Olaf van der Spek
Hi,
I'm running a reverse proxy with nginx and using certbot for ssl. It's been
working great but recently with an php server installation it's been giving
me problems.
I get access to the index but any other page I get a 404 error from nginx.

404 Not Found
nginx/1.14.0 (Ubuntu)

This is my conf file
server {

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

    ###################################################
    # Change "yoururl.com" to your host name

    server_name my-domain;

#    location / {
#        try_files $uri $uri/ /index.php?q=$uri&$args;
#    }

    location /site/ {
      if (!-e $request_filename){
        rewrite ^/site/(.*)$ /site/index.php break;
      }
    }location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param PATH_TO_FRAMEWORKS /var/www/frameworks/;
        fastcgi_param CORE_TYPE frameworks;
        fastcgi_param IS_DEV true;
        include fastcgi_params;
    }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
   }

    location ~ /\. {
        deny all;
    }

    location ~* /(?:uploads|files)/.*\.php$ {
        deny all;
    }location / {
   proxy_pass http://my-server-ip/;
 }





    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/my-domain/fullchain.pem; #$
    ssl_certificate_key /etc/letsencrypt/live/my-domain/privkey.pem;$
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = my-domain) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
    listen 80;

    server_name my-domain;
    return 404; # managed by Certbot


}


Any had similar problems? It's nginx having a different configuration for
php?
Just in case I have tried commenting the last lines which appears to send
the 404, but it did the same thing.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,287003,287003#msg-287003

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Nginx php reverse proxy problem

Francis Daly
On Wed, Feb 12, 2020 at 07:43:11AM -0500, adrian.hilt wrote:

Hi there,

> I'm running a reverse proxy with nginx and using certbot for ssl. It's been
> working great but recently with an php server installation it's been giving
> me problems.
> I get access to the index but any other page I get a 404 error from nginx.

>     location /site/ {
>       if (!-e $request_filename){
>         rewrite ^/site/(.*)$ /site/index.php break;
>       }

You might be happier there with "last" instead of "break".

http://nginx.org/r/rewrite

But you might be happier still, replacing the three lines with something
like

    try_files $uri $uri/ /site/index.php;

which is the usual nginx way to "fall back" to php processing.

Good luck with it,

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Nginx php reverse proxy problem

Olaf van der Spek
Thanks, I just tried and it didn't work.
If I use the ip to access I don't have any problem, when it goes throw nginx
is the problem.

Maybe are there some parameters in the php config of my server that I need
to change?

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,287003,287071#msg-287071

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Nginx php reverse proxy problem

Francis Daly
On Thu, Feb 20, 2020 at 08:10:14AM -0500, adrian.hilt wrote:

Hi there,

> Thanks, I just tried and it didn't work.

What config do you use?

What request do you make?

What response do you get?

What response do you want instead?

> If I use the ip to access I don't have any problem, when it goes throw nginx
> is the problem.

I don't understand what that means.

Can you copy-paste the (e.g.) "curl -v" output for a working and failing
request? Feel free to edit any private data; but if you do, please edit
it consistently.

> Maybe are there some parameters in the php config of my server that I need
> to change?

Maybe.

But guessing may not be the most efficient way to resolve the problem.

Cheers,

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx