situation with friendly urls

R
  • 30 Mar '23
Hi list, I have a situation that I want to share, we develop a small
application in php that has friendly urls, it has a section in English
and the other in Spanish, but when we put it in the backend server the
project does not load correctly.

I want to share a bit about the design of our infrastructure:

users =========> Proxy reverse ===========backend server

I've tried different configurations on the backend server and the
reverse proxy, but still can't get it to load.

For example, in the backend I put this type of application to load:

location /

    {

      try_files $uri $uri/ /index.php?$args;
#      try_files $uri /index.php;
      root /var/tmp/sites/site.com/htdocs;
       index index.php index.html index.htm;

    }

proxy reverse :

location / {

        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_set_header Host $host;

proxy_set_header X-Real-IP  $remote_addr;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  proxy_connect_timeout 900s;

        proxy_send_timeout 900s;

        proxy_read_timeout 900s;

proxy_buffer_size 64k;

proxy_buffers 16 32k;

proxy_busy_buffers_size 64k;

proxy_redirect off;

proxy_request_buffering off;

proxy_buffering off;

        proxy_pass http://backend2;

    }

I don't see any errors in the log,

any advice?

-- 
rickygm

http://gnuforever.homelinux.com
D
  • 30 Mar '23
Check to make sure the file is stored as UTF-8 Unicode instead of ANSI.

I once had an issue where NGINX wouldn't load and the log showed nothing
useful.  It turned out I had to convert the file to UTF-8 Unicode to get it
to work again.

On Thu, Mar 30, 2023, 7:16 AM Rick Gutierrez <xserverlinux at gmail.com> wrote:

> Hi list, I have a situation that I want to share, we develop a small
> application in php that has friendly urls, it has a section in English
> and the other in Spanish, but when we put it in the backend server the
> project does not load correctly.
>
> I want to share a bit about the design of our infrastructure:
>
> users =========> Proxy reverse ===========backend server
>
> I've tried different configurations on the backend server and the
> reverse proxy, but still can't get it to load.
>
> For example, in the backend I put this type of application to load:
>
> location /
>
>     {
>
>       try_files $uri $uri/ /index.php?$args;
> #      try_files $uri /index.php;
>       root /var/tmp/sites/site.com/htdocs;
>        index index.php index.html index.htm;
>
>     }
>
>
>
> proxy reverse :
>
> location / {
>
>
>         proxy_http_version 1.1;
>         proxy_set_header Connection "";
>         proxy_set_header Host $host;
>
> proxy_set_header X-Real-IP  $remote_addr;
>
>         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
>
>   proxy_connect_timeout 900s;
>
>         proxy_send_timeout 900s;
>
>         proxy_read_timeout 900s;
>
> proxy_buffer_size 64k;
>
> proxy_buffers 16 32k;
>
> proxy_busy_buffers_size 64k;
>
> proxy_redirect off;
>
> proxy_request_buffering off;
>
> proxy_buffering off;
>
>         proxy_pass http://backend2;
>
>
>     }
>
> I don't see any errors in the log,
>
> any advice?
>
> --
> rickygm
>
> http://gnuforever.homelinux.com
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> https://mailman.nginx.org/mailman/listinfo/nginx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20230330/a504060a/attachment.htm>
D
  • 30 Mar '23
Another thing to try would be to enable debug to your output log.

Add this line to the top of your nginx.conf file and restart NGINX:

error_log  /var/log/nginx/error.log debug;

This assumes you have built NGINX with the configure option of --with-debug

Here's the URL to the NGINX docs for convenience:

https://docs.nginx.com/nginx/admin-guide/monitoring/debugging/

On Thu, Mar 30, 2023, 7:16 AM Rick Gutierrez <xserverlinux at gmail.com> wrote:

> Hi list, I have a situation that I want to share, we develop a small
> application in php that has friendly urls, it has a section in English
> and the other in Spanish, but when we put it in the backend server the
> project does not load correctly.
>
> I want to share a bit about the design of our infrastructure:
>
> users =========> Proxy reverse ===========backend server
>
> I've tried different configurations on the backend server and the
> reverse proxy, but still can't get it to load.
>
> For example, in the backend I put this type of application to load:
>
> location /
>
>     {
>
>       try_files $uri $uri/ /index.php?$args;
> #      try_files $uri /index.php;
>       root /var/tmp/sites/site.com/htdocs;
>        index index.php index.html index.htm;
>
>     }
>
>
>
> proxy reverse :
>
> location / {
>
>
>         proxy_http_version 1.1;
>         proxy_set_header Connection "";
>         proxy_set_header Host $host;
>
> proxy_set_header X-Real-IP  $remote_addr;
>
>         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
>
>   proxy_connect_timeout 900s;
>
>         proxy_send_timeout 900s;
>
>         proxy_read_timeout 900s;
>
> proxy_buffer_size 64k;
>
> proxy_buffers 16 32k;
>
> proxy_busy_buffers_size 64k;
>
> proxy_redirect off;
>
> proxy_request_buffering off;
>
> proxy_buffering off;
>
>         proxy_pass http://backend2;
>
>
>     }
>
> I don't see any errors in the log,
>
> any advice?
>
> --
> rickygm
>
> http://gnuforever.homelinux.com
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> https://mailman.nginx.org/mailman/listinfo/nginx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20230330/19ab31e3/attachment.htm>
R
  • 31 Mar '23
El jue, 30 mar 2023 a las 19:32, Dan Swaney (<justdan23 at gmail.com>) escribió:
>
> Check to make sure the file is stored as UTF-8 Unicode instead of ANSI.
>
> I once had an issue where NGINX wouldn't load and the log showed nothing useful.  It turned out I had to convert the file to UTF-8 Unicode to get it to work again.
>

Hi Dan ,  I have it encoded in that format.
R
  • 31 Mar '23
El jue, 30 mar 2023 a las 19:39, Dan Swaney (<justdan23 at gmail.com>) escribió:
>
> Another thing to try would be to enable debug to your output log.
>
> Add this line to the top of your nginx.conf file and restart NGINX:
>
> error_log  /var/log/nginx/error.log debug;
>
>
> This assumes you have built NGINX with the configure option of --with-debug
>
Let me try, I'll put it in the reverse proxy
R
  • 1 Apr '23
El jue, 30 mar 2023 a las 23:12, Rick Gutierrez
(<xserverlinux at gmail.com>) escribió:

> Let me try, I'll put it in the reverse proxy

I send the log, there is a folder that nginx is not loading for me "assets"

https://pastebin.com/JMP3n7iB

I think there could be an error, what do you think?
-- 
rickygm

http://gnuforever.homelinux.com
R
  • 9 Apr '23
El sáb, 1 abr 2023 a las 16:49, Rick Gutierrez
(<xserverlinux at gmail.com>) escribió:
>
> El jue, 30 mar 2023 a las 23:12, Rick Gutierrez
> (<xserverlinux at gmail.com>) escribió:
>
Hi here again, I have tried different configurations but I cannot get
the project website to load correctly.

### backend config

location /assets/ {

   alias /var/www/sites/netsoluciones.com/htdocs/assets/;

}

location /css/ {

   alias /var/www/sites/netsoluciones.com/htdocs/css/;

}

location /img/ {

   alias /var/www/sites/netsoluciones.com/htdocs/img/;

}

location /vendor/ {

   alias /var/www/sites/netsoluciones.com/htdocs/vendor/;

}

https://pastebin.com/JMP3n7iB

any idea , suggestion?

-- 
rickygm

http://gnuforever.homelinux.com
F
  • 9 Apr '23
On Sat, Apr 08, 2023 at 11:29:25PM -0400, Rick Gutierrez wrote:

Hi there,

> Hi here again, I have tried different configurations but I cannot get
> the project website to load correctly.

When you say that it does not load correctly, can you show one specific
request that does not get the response that you want it to get? That
should make it easier to identify where things are going wrong.

For what it is worth: the debug log that you show, does not appear to
come from a system that is using the configuration that you show.

So it is possible that the configuration that you are changing, is not
the one that the running nginx is actively using.

(Or maybe you are only showing a part of the configuration that is not
used in this request?)

The debug log does not show the locations /assets/ or /css/ or the like;
it mainly shows locations related to the third-party pagespeed module.

>From what you describe, the browser should make a request to the "front"
nginx server, which should use its proxy_pass config to make a request
to the "backend" nginx server, which should then do whatever it is
configured to do.

It is not clear to me what request is being made to the "front" server,
that is not being handled as you want it to be.

> location /assets/ {
> 
>    alias /var/www/sites/netsoluciones.com/htdocs/assets/;
> 
> }

> https://pastebin.com/JMP3n7iB

That seems to show a request for
/assets/images/empresa/x26910210_152867885365030_7535289409698400565_o.png.pagespeed.ic.B57rrxzkqD.webp
that is handled in the regex location ~
".*\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+", and not in the
prefix location /assets/.

> any idea , suggestion?

More information.

It looks like you want the "/assets/" request to be handled by serving a
file from the filesystem; but that seems unrelated to php, friendly urls,
and two languages.

So if you can describe how you want one specific request to be handled,
and can show how it actually is handled, maybe the first place where
those two things differ can be identified.

Cheers,

    f
-- 
Francis Daly        francis at daoine.org
R
  • 9 Apr '23
El dom, 9 abr 2023 a las 7:27, Francis Daly (<francis at daoine.org>) escribió:
>

Hi Francis :)

>
> When you say that it does not load correctly, can you show one specific
> request that does not get the response that you want it to get? That
> should make it easier to identify where things are going wrong.

https://netsoluciones.com

This is the site, for example when I want to load the site in English
it doesn't do it, it doesn't load the images and css either.

> For what it is worth: the debug log that you show, does not appear to
> come from a system that is using the configuration that you show.

I think this is my mistake, I show you the backend config and then the
reverse proxy.

### backend config of nignx

location /

    {

      try_files $uri $uri/ /index.php?$args;

      root /var/www/sites/netsoluciones.com/htdocs;
       index index.php index.html index.htm;
    }

location /assets/ {

   alias /var/www/sites/netsoluciones.com/htdocs/assets/;

}

location /css/ {

   alias /var/www/sites/netsoluciones.com/htdocs/css/;

}

location /img/ {

   alias /var/www/sites/netsoluciones.com/htdocs/img/;

}

location /vendor/ {

   alias /var/www/sites/netsoluciones.com/htdocs/vendor/;

}

    # Scripts en PHP:

location ~ "\.php$" {

fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
       fastcgi_index  index.php;

#        fastcgi_pass 127.0.0.1:9000;

### REVERSE PROXY

upstream backend00 {

    server X.X.X.X:80;

    keepalive 2;

}

server {

    if ($host = www.netsoluciones.com) {

        return 301 https://$host$request_uri;

    } # managed by Certbot

    if ($host = netsoluciones.com) {

        return 301 https://$host$request_uri;

    } # managed by Certbot

listen 80;

        server_name www.netsoluciones.com netsoluciones.com; #YourIP
or domain
pagespeed unplugged;

        return 301 https://$server_name$request_uri;  # redirect all to use ssl

}

server {

    listen 443 ssl http2;

    server_name www.netsoluciones.com netsoluciones.com;

    add_header Cache-Control "max-age=86400,  public";

#    ssl on;

    ssl_certificate /etc/letsencrypt/live/DDDD/fullchain.pem; #
managed by Certbot

    ssl_certificate_key /etc/letsencrypt/live/DDDD/privkey.pem; #
managed by Certbot

    ssl_trusted_certificate
/etc/letsencrypt/live/www.netsoluciones.com/chain.pem;

    ssl_protocols  TLSv1.3 TLSv1.2;

    ssl_ciphers
ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GC

M-SHA384:ECDHE-RSA-AES256-SHA384;

    ssl_prefer_server_ciphers on;

    ssl_stapling on;

    ssl_stapling_verify on;

    add_header Strict-Transport-Security "max-age=31557600; includeSubDomains";

    add_header X-Xss-Protection "1; mode=block" always;

    add_header X-Frame-Options "SAMEORIGIN" always;

    add_header X-Content-Type-Options "nosniff" always;

    include /etc/nginx/default.d/pagespeed_filters.conf;

    keepalive_requests 1000;

    keepalive_timeout  5 5;

    ssl_session_cache shared:SSL:10m;

    ssl_session_timeout  30m;

     brotli on;

     brotli_comp_level 4;

     brotli_types text/plain text/css application/json
application/javascript application/x-javascript text/xml app

lication/xml application/xml+rss text/javascript;

location / {

        proxy_http_version 1.1;

        proxy_set_header Connection "";

        proxy_set_header Host $host;

proxy_set_header X-Real-IP  $remote_addr;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_request_buffering off;

proxy_buffering off;
        proxy_pass http://backend00;

>
> So it is possible that the configuration that you are changing, is not
> the one that the running nginx is actively using.
>
> (Or maybe you are only showing a part of the configuration that is not
> used in this request?)
>
> The debug log does not show the locations /assets/ or /css/ or the like;
> it mainly shows locations related to the third-party pagespeed module.
>
> From what you describe, the browser should make a request to the "front"
> nginx server, which should use its proxy_pass config to make a request
> to the "backend" nginx server, which should then do whatever it is
> configured to do.
>
> It is not clear to me what request is being made to the "front" server,
> that is not being handled as you want it to be.
>
> > location /assets/ {
> >
>

I adapted that last configuration in the backend from an example I saw
on the internet of a person with a similar problem, but it doesn't
work for me so I'll delete it.

> More information.
>
> It looks like you want the "/assets/" request to be handled by serving a
> file from the filesystem; but that seems unrelated to php, friendly urls,
> and two languages.
>
> So if you can describe how you want one specific request to be handled,
> and can show how it actually is handled, maybe the first place where
> those two things differ can be identified.
>
> Cheers,
>

I hope that by looking at the site you have a better idea.

thnk.

-- 
rickygm

http://gnuforever.homelinux.com
F
  • 10 Apr '23
On Sun, Apr 09, 2023 at 04:08:30PM -0400, Rick Gutierrez wrote:
> El dom, 9 abr 2023 a las 7:27, Francis Daly (<francis at daoine.org>) escribió:

Hi there,

> https://netsoluciones.com
> 
> This is the site, for example when I want to load the site in English
> it doesn't do it, it doesn't load the images and css either.

When I try loading that site now, I see lots of requests to things that
end in ".css" that get a HTTP 404 response; I do not see any images.

The first one is for https://netsoluciones.com/assets/helpers/animate.css.

Based on the config you provided, that should be handled by
the "front" nginx by doing a proxy_pass to the "back" nginx;
and the "back" nginx should provide the content of the file
/var/www/sites/netsoluciones.com/htdocs/assets/helpers/animate.css.

The end result is a 404 File Not Found.

Does that file exist on the back-end nginx server? What do those nginx
logs say for this request? Did the request get to it at all, or did the
request stop at the front-end nginx server? What do *those* nginx logs
say for this request?

If you make a test request like

    curl -i https://netsoluciones.com/assets/helpers/animate.css

do you see the response that you expect? (Which should probably be HTTP
200 along with the content of the expected file.)

Slightly strangely: when I do that using curl, I get a HTTP 200 response
but with html not css; where my browser gets a HTTP 404 response. Maybe
they are talking to different servers, or maybe there is some config
that handles the request differently based on something other than the url.

> I hope that by looking at the site you have a better idea.

Not really, no, sorry.

I do not know how things are intended to look, so I cannot tell which
parts are not that way.

Cheers,

    f
-- 
Francis Daly        francis at daoine.org
R
  • 10 Apr '23
El lun, 10 abr 2023 a las 4:27, Francis Daly (<francis at daoine.org>) escribió:
>
> On Sun, Apr 09, 2023 at 04:08:30PM -0400, Rick Gutierrez wrote:
> > El dom, 9 abr 2023 a las 7:27, Francis Daly (<francis at daoine.org>) escribió:
>
> Hi there,
>
> > https://netsoluciones.com
> >
> > This is the site, for example when I want to load the site in English
> > it doesn't do it, it doesn't load the images and css either.
>
> When I try loading that site now, I see lots of requests to things that
> end in ".css" that get a HTTP 404 response; I do not see any images.
>
> The first one is for https://netsoluciones.com/assets/helpers/animate.css.
>
> Based on the config you provided, that should be handled by
> the "front" nginx by doing a proxy_pass to the "back" nginx;
> and the "back" nginx should provide the content of the file
> /var/www/sites/netsoluciones.com/htdocs/assets/helpers/animate.css.
>
> The end result is a 404 File Not Found.

Sorry Francis the folder path was wrong, update and  try again

>
> Does that file exist on the back-end nginx server? What do those nginx
> logs say for this request? Did the request get to it at all, or did the
> request stop at the front-end nginx server? What do *those* nginx logs
> say for this request?
>
> If you make a test request like
>
>         curl -i https://netsoluciones.com/assets/helpers/animate.css
>
> do you see the response that you expect? (Which should probably be HTTP
> 200 along with the content of the expected file.)
>
> Slightly strangely: when I do that using curl, I get a HTTP 200 response
> but with html not css; where my browser gets a HTTP 404 response. Maybe
> they are talking to different servers, or maybe there is some config
> that handles the request differently based on something other than the url.
>
> > I hope that by looking at the site you have a better idea.
>
> Not really, no, sorry.
>
> I do not know how things are intended to look, so I cannot tell which
> parts are not that way.
>

Let me see if I send a screenshot, locally it loads fine.

-- 
rickygm

http://gnuforever.homelinux.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: home.png
Type: image/png
Size: 521898 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20230410/053e37cd/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: productos.png
Type: image/png
Size: 149255 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20230410/053e37cd/attachment-0003.png>
F
  • 10 Apr '23
On Mon, Apr 10, 2023 at 11:07:11AM -0400, Rick Gutierrez wrote:

Hi there,

> Sorry Francis the folder path was wrong, update and  try again

I now see some more things getting good responses, but there are still
lots of missing images, and the browser "developer tools" network
console shows lots of failing requests.

I do not know which ones are broken because files are not where they are
expected to be, and which ones are broken because of the "friendly url"
issue you are reporting.

> Let me see if I send a screenshot, locally it loads fine.

When I load the web site from the public internet, I do not see what
specific url should lead to those screenshots.

If you can identify one particular url, where the response from nginx
is not what you want it to be, then maybe that one can be analysed in
more detail.

Otherwise, I'm afraid that "something does not work" is not enough of
a problem report for further action.

Cheers,

    f
-- 
Francis Daly        francis at daoine.org