1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Nginx does not serve/proxy path if it is missing ending slash

Discussion in 'Nginx' started by postcd, Aug 18, 2023.

  1. #1
    Hello dear Nginx users, being amateur user I wanted to ask You for your help.

    My Nginx configuration is properly serving a webpage when visiting:
    server.my.name
    my.name
    my.name/rooms
    my.name/room/abc
    my.name/r/abc/

    but not when i visit:
    my.name/r/abc
    (note that same path works when it has trailing slash)

    without slash, it redirects to
    http://127.3.2.1:4242/r/abc/ 
    Code (markup):
    my configuration file is:

    # cat /etc/nginx/nginx.conf
    
    #user nobody;
    worker_processes 1;
    
    #error_log logs/error.log;
    #error_log logs/error.log notice;
    #error_log logs/error.log info;
    #pid logs/nginx.pid;
    
    events {
    worker_connections 1024;
    }
    
    http {
    access_log off;
    access_log /var/log/nginx/access.log;
    #access_log logs/access.log main;
    error_log on;
    #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    # '$status $body_bytes_sent "$http_referer" '
    # '"$http_user_agent" "$http_x_forwarded_for"';
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    #tcp_nopush on;
    #keepalive_timeout 0;
    keepalive_timeout 65;
    #gzip on;
    # include /etc/nginx/sites-enabled/*;
    
    server {
    server_name 127.0.0.1 server.my.name;
    listen 80;
    listen [::]:80;
    listen 443 ssl; # managed by Certbot
    listen [::]:443 ssl;
    ssl_certificate /etc/letsencrypt/live/my.name/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/my.name/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    
    location / {
    root /var/www/html;
    }
    
    index index-server-var-www.html index.htm index.php
    try_files $uri $uri/ =404;
    
    location ~ /\.ht {
    deny all;
    }
    
    location = /favicon.ico {
    log_not_found off;
    access_log off;
    }
    }
    
    server {
    server_name https my.name www.my.name;
    client_max_body_size 10M;
    location /static/ {
    autoindex off;
    root /usr/lib/python3/dist-packages/sogs;
    # try_files $uri /404.html;
    # error_page 404 =200 /404.html;
    }
    location = /404.html {
    root /var/lib/session-open-group-server;
    }
    location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass http://127.3.2.1:4242$request_uri;
    # try_files $uri $uri/ =404;
    # if ($request_uri = "?public_key=") { return 301 /; }
    }
    listen 80;
    listen [::]:80;
    listen 443 ssl; # managed by Certbot
    listen [::]:443 ssl;
    ssl_certificate /etc/letsencrypt/live/my.name/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/my.name/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    
    # error_page 404 /404.html;
    # error_page 404 =200 /404.html;
    # try_files $uri /404.html;
    
    }
    }
    
    Code (markup):
    Since i think that i am not linking to any other .conf files, issue must be in above file, but where to correct it please?
     
    postcd, Aug 18, 2023 IP
  2. FlyPastaMonster

    FlyPastaMonster Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    Hello.
    What does the log write?

    In any case, try adding a slash at the end of the proxy_pass line, before the semicolon
     
    FlyPastaMonster, Sep 18, 2023 IP
  3. postcd

    postcd Well-Known Member

    Messages:
    1,035
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    190
    #3
    This worked in one web browser for my.name/r/abc
    proxy_pass http://127.3.2.1:4242$request_uri/;
    Code (markup):
    but unfortunately it broken workings of the app that depends on the URL
    http://127.3.2.1:4242$request_uri; 
    Code (markup):
    .

    Access_log line was like: "GET /r/abc HTTP/1.1" 200 318 "-" "Mozilla/5.0
    Error log lines not found any around that time.
     
    postcd, Sep 18, 2023 IP
  4. hanoidesign

    hanoidesign Active Member

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #4
    I think the redirect is caused by proxied server (perhaps it has behavior to redirect from 127.3.2.1:4242/r/abc to 127.3.2.1:4242/r/abc/).
    Try adding proxy_redirect to correct the header of server response like:

    proxy_redirect http://127.3.2.1:4242/ http://$host:$server_port/;
    Code (markup):
    Doc: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect
     
    hanoidesign, Sep 20, 2023 at 1:22 AM IP
    postcd likes this.
  5. shaghayegh1122

    shaghayegh1122 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    با سلام
    فروش پمپ آب
     
    shaghayegh1122, Sep 22, 2023 at 11:24 AM IP
  6. shaghayegh1122

    shaghayegh1122 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #6
    فروش پمپ آب
     
    shaghayegh1122, Sep 22, 2023 at 11:24 AM IP
  7. shaghayegh1122

    shaghayegh1122 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #7
    فروش پمپ آب
     
    shaghayegh1122, Sep 22, 2023 at 11:26 AM IP
  8. shaghayegh1122

    shaghayegh1122 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #8
    فروش پمپ آب در اصفهان
     
    shaghayegh1122, Sep 22, 2023 at 11:32 AM IP
  9. shaghayegh1122

    shaghayegh1122 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #9
    https://tasisatsepahan.com/product-category/water-pump/
     
    shaghayegh1122, Sep 22, 2023 at 11:33 AM IP