nginx loads the default page despite my proxy_pass configuration

This should be a very straight forward nginx configuration I would think, but it will only show me the default nginx homepage. I’ve even deleted the default file from /etc/nginx/sites-* to avoid having it possibly interfere at all.

I have the following file in /etc/nginx/sites-available/my.domain:

server {
    listen 80;
    listen [::]:80;
    server_name my.domain.com;

    location / {
        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_set_header        X-Forwarded-Proto $scheme;
        proxy_pass              http://localhost:3000/;
        proxy_read_timeout      90;
    }
}

I have the following symlink in sites-enabled:

my.domain -> /etc/nginx/sites-available/my.domain

I have checked that my configuration seems to be all right with nginx -t and reloaded it with nginx -s reload.

nginx -T outputs the following and I don’t see anything wrong with it:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# configuration file /etc/nginx/nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

# configuration file /etc/nginx/modules-enabled/50-mod-http-image-filter.conf:
load_module modules/ngx_http_image_filter_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-http-xslt-filter.conf:
load_module modules/ngx_http_xslt_filter_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-mail.conf:
load_module modules/ngx_mail_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-stream.conf:
load_module modules/ngx_stream_module.so;

# configuration file /etc/nginx/mime.types:

types {
    text/html                             html htm shtml;
    text/css                              css;
    text/xml                              xml;
    image/gif                             gif;
    image/jpeg                            jpeg jpg;
    application/javascript                js;
    application/atom+xml                  atom;
    application/rss+xml                   rss;

    text/mathml                           mml;
    text/plain                            txt;
    text/vnd.sun.j2me.app-descriptor      jad;
    text/vnd.wap.wml                      wml;
    text/x-component                      htc;

    image/png                             png;
    image/tiff                            tif tiff;
    image/vnd.wap.wbmp                    wbmp;
    image/x-icon                          ico;
    image/x-jng                           jng;
    image/x-ms-bmp                        bmp;
    image/svg+xml                         svg svgz;
    image/webp                            webp;

    application/font-woff                 woff;
    application/java-archive              jar war ear;
    application/json                      json;
    application/mac-binhex40              hqx;
    application/msword                    doc;
    application/pdf                       pdf;
    application/postscript                ps eps ai;
    application/rtf                       rtf;
    application/vnd.apple.mpegurl         m3u8;
    application/vnd.ms-excel              xls;
    application/vnd.ms-fontobject         eot;
    application/vnd.ms-powerpoint         ppt;
    application/vnd.wap.wmlc              wmlc;
    application/vnd.google-earth.kml+xml  kml;
    application/vnd.google-earth.kmz      kmz;
    application/x-7z-compressed           7z;
    application/x-cocoa                   cco;
    application/x-java-archive-diff       jardiff;
    application/x-java-jnlp-file          jnlp;
    application/x-makeself                run;
    application/x-perl                    pl pm;
    application/x-pilot                   prc pdb;
    application/x-rar-compressed          rar;
    application/x-redhat-package-manager  rpm;
    application/x-sea                     sea;
    application/x-shockwave-flash         swf;
    application/x-stuffit                 sit;
    application/x-tcl                     tcl tk;
    application/x-x509-ca-cert            der pem crt;
    application/x-xpinstall               xpi;
    application/xhtml+xml                 xhtml;
    application/xspf+xml                  xspf;
    application/zip                       zip;

    application/octet-stream              bin exe dll;
    application/octet-stream              deb;
    application/octet-stream              dmg;
    application/octet-stream              iso img;
    application/octet-stream              msi msp msm;

    application/vnd.openxmlformats-officedocument.wordprocessingml.document    docx;
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet          xlsx;
    application/vnd.openxmlformats-officedocument.presentationml.presentation  pptx;

    audio/midi                            mid midi kar;
    audio/mpeg                            mp3;
    audio/ogg                             ogg;
    audio/x-m4a                           m4a;
    audio/x-realaudio                     ra;

    video/3gpp                            3gpp 3gp;
    video/mp2t                            ts;
    video/mp4                             mp4;
    video/mpeg                            mpeg mpg;
    video/quicktime                       mov;
    video/webm                            webm;
    video/x-flv                           flv;
    video/x-m4v                           m4v;
    video/x-mng                           mng;
    video/x-ms-asf                        asx asf;
    video/x-ms-wmv                        wmv;
    video/x-msvideo                       avi;
}

# configuration file /etc/nginx/sites-enabled/my.domain:
server {
    listen 80;
    listen [::]:80; 
    server_name my.domain.com;

    location / {
    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_set_header        X-Forwarded-Proto $scheme;
    proxy_pass              http://localhost:3000/;
    proxy_read_timeout      90;
    }
}

What am I missing here? Is there some default configuration that’s overriding what I’ve set up?

nginx – Apache alias ignored when used with ProxyPass

I’m trying to install yotter on my server, and I want to use apache instead of nginx. The installation guide only lists an nginx configuration file, which I’m trying to “translate”.

The config is three different proxy routes, the first one leading to a docker container, the second one (/static/) to a directory with stylesheets and stuff like that and the last one to a unix domain socket.

In my case, the first route seems to work (I can access the site), but each request to a static ressource returns a 404. It looks like each requests uses the docker ProxyPass directive (no matter the order: if I put that one last (see below), it’s still the only one used).

This is (a part of) the log file created:

yotter.domain.tld - - (12/Aug/2021:21:14:21 +0200) "GET /static/favicons/favicon.ico HTTP/1.1" 404 1935 file=proxy:http://127.0.0.1:5000/static/favicons/favicon.ico
yotter.domain.tld - - (12/Aug/2021:21:15:54 +0200) "GET /index HTTP/1.1" 200 1126 file=proxy:http://127.0.0.1:5000/index
yotter.domain.tld - - (12/Aug/2021:21:15:54 +0200) "GET /static/semantic/semantic.min.css HTTP/1.1" 404 1935 file=proxy:http://127.0.0.1:5000/static/semantic/semantic.min.css

What could be the reason for this?

This is the nginx config:

server {
    listen 80;
    server_name <example.com>; # ChangeME
    access_log off;

    location / {
        proxy_pass http://127.0.0.1:5000;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }

    location /static/ {
        root /home/ubuntu/Yotter/app/; # Change this depending on where you clone Yotter
        sendfile on;
        aio threads=default;
    }

    location ~ (^/videoplayback$|/videoplayback/|/vi/|/a/) {
        proxy_pass http://unix:/var/run/ytproxy/http-proxy.sock;
        add_header Access-Control-Allow-Origin *;
        sendfile on;
        tcp_nopush on;
        aio_write on;
        aio threads=default;
        directio 512;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }
}

And here is what I have so far:

<VirtualHost *:443>
        ServerName yotter.domain.tld

        LogFormat "%v %l %u %t "%r" %>s %b file=%f" commonvhost
        CustomLog ${APACHE_LOG_DIR}/yotter_access.log commonvhost

        SSLEngine on
        SSLCertificateFile /etc/letsencrypt/live/domain.tld/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/domain.tld/privkey.pem

        <Location "/">
                ProxyPass http://127.0.0.1:5000/
                ProxyPassReverse http://127.0.0.1:5000/
        </Location>


        <Location "/static">
                Alias "/var/www/Yotter/app/static"
        </Location>

        <Directory "/var/www/Yotter/app/">
                Require all granted
        </Directory>


        <LocationMatch (^/videoplayback$|/videoplayback/|/vi/|/a/)>
                ProxyPass unix:///var/run/ytproxy/http-proxy.sock
                ProxyPassReverse unix:///var/run/ytproxy/http-proxy.sock
                Header add Acces-Control-Allow-Origin: *
        </LocationMatch>

</VirtualHost>

or

<VirtualHost *:443>
        ServerName yotter.domain.tld

        LogFormat "%v %l %u %t "%r" %>s %b file=%f" commonvhost
        CustomLog ${APACHE_LOG_DIR}/yotter_access.log commonvhost

        SSLEngine on
        SSLCertificateFile /etc/letsencrypt/live/domain.tld/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/domain.tld/privkey.pem


        Alias "/static" "/var/www/Yotter/app/static"

        <Directory "/var/www/Yotter/app/">
                Require all granted
        </Directory>


        <LocationMatch (^/videoplayback$|/videoplayback/|/vi/|/a/)>
                ProxyPass unix:///var/run/ytproxy/http-proxy.sock
                ProxyPassReverse unix:///var/run/ytproxy/http-proxy.sock
                Header add Acces-Control-Allow-Origin: *
        </LocationMatch>


        ProxyPass / http://127.0.0.1:5000/
        ProxyPassReverse / http://127.0.0.1:5000/

</VirtualHost>

NGINX Proxy_Pass convert url /categorieën/ to /categorieën/

i have pass https://apptest.ddd.se:92/categorieën/ to nginx proxy this is the output http://localhost:8080/categorieën/
any idea?

django – How to configure nginx proxy_pass to serve http images from https website?

I have django website and remote image storage. I want to proxy for example /images/ from django to server 10.0.0.40/images/.

location /images/ {
    proxy_pass http://10.0.0.40/images/;
}

No errors in nginx. But django returns Page not found should I set something in urls.py or configuration is not so simple? And will it work in Chrome browser at all? Because https -> http doesn’t work in Chrome.

Expected:

test.com/images/test.jpg -> http://10.0.0.40/images/test.jpg

NGINX Get local IP for proxy_pass

Is it possible to pass in a variable such as $server_addr into proxy_pass.

proxy_pass      http://$server_addr:8096/;

If I do this, I run into issues where it doesn’t load. Is this possible on what I’m doing?

NGINX – Is it possible to specify custom locations if the root location is using proxy_pass?

I’m a server noob, so I might be wrong about what’s happening here and how to solve it, but anyway. I have a node server running on port 3000 and served at the base of my domain.

server {
    server_name blahblah.com www.blahblah.com; # managed by Certbot

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location /test/ {
        index index.html
        root /var/www/html;
    }
    
    ...

I want to add a new static location (test) that should override the proxy_pass setup above, but I think the / block is consuming everything that comes after it because when I visit /test it takes me to my node app’s custom 404 page. Is this something that’s possible to make work?

Nginx proxy_pass rewrite URL and Headers

Solved, the problem is nginx regex only match path or

/httpbin.org/anything

not parameter or query string

?test=data@cookieValue

to solve the problem I change the URL to

http://localhost/app/cookieValue/httpbin.org/anything?test=data

and here the config

location ~ ^/app/((^/)+)/(.*){
    resolver 8.8.8.8;
    proxy_pass https://$2$is_args$args;
    proxy_set_header  Cookie myCookie=$1;
}

linux – ProxyPass to https url Need help for version 2.4 apache

Team,
I am really confused and tried multiple things to achieve this as for my RHEL6 host below URL working fine :

ProxyPass /lookup https://spidr2-qa.myserver.com/lookup
ProxyPassReverse /lookup https://spidr2-qa.myserver.com/lookup

ProxyPass /distribution https://spidr2-qa.myserver.com/distribution
ProxyPassReverse /distribution https://spidr2-qa.myserver.com/distribution

But after upgrade to RHEL7 and apache 2.4 above code does not work.

What is required to make https (ProxyPass call to work above block)? Above code works fine before.
Now I am getting 404 code error. And this URL is of other hosts URL but it try to find context in same host. Ideally it should redirect to other host and make it work.

Using Haproxy pass-through frontend and nginx proxy_pass directive on backend

How to use proxy_pass rewrite on backend, while having a haproxy pass-through on frontend. Frontend doesn’t terminate SSL and passes all requests to backend.

And on backend having this following config, to rewrite using proxy_pass.

server {
    listen 443 ssl http2 proxy_protocol;
    set_real_ip_from x.x.x.x;
    real_ip_header proxy_protocol;
    
    location ~ ^/file.js {
        rewrite /file.php?$args break;
        proxy_buffering off;
        proxy_pass https://$server_name:443;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect off;
   }
}

Currently I’m getting 200 status with a 500 error page on it.

docker – nginx proxy_pass return 502 Bad Gateway

I’m building nginx for reverse_proxy with Spring and Docker

Here is my configuration.

nginx.conf

user  proxy;
worker_processes  auto;
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 {
    log_format  main  '$remote_addr - $remote_user ($time_local) "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  logs/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include       mime.types;
    default_type  application/octet-stream;

    include /home/wertkey/nginx/conf/conf.d/*.conf;

    client_max_body_size 200M;
    client_header_buffer_size  48k;

    server {
        listen       7070 default_server;
        listen       (::):7070 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        location / {
        }

        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
}

conf.d/default.conf

server {
    listen 7070;
    server_name something.com;

    proxy_connect_timeout   900s;
    proxy_send_timeout      900s;
    proxy_read_timeout      900s;
    send_timeout            900s;

    location ^~ /editor/ {
        proxy_pass http://localhost:8081;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;

        rewrite ^/editor/(/.*)$ $1 break;
    }
}

docker

CONTAINER ID        IMAGE        COMMAND                  CREATED             STATUS              PORTS                    NAMES
a6a6a98a25a9        editor       "/bin/sh -c /usr/l..."   8 minutes ago       Up 8 minutes        0.0.0.0:8081->8080/tcp   editor

My spring server is running at 7070 port.
I want to be this way.

  1. request something.com:7070/api
  2. nginx proxy_pass to 8081
  3. and docker 8081 -> 8080

But response always return 502 Bad Gateway

What am i missing?

+
I am currently running two nginxs on the same server.
One is running at 8080 port and the other is running at 7070 port.
8080 nginx is for web servers and 7070 nginx is for proxy purposes.
The log does not appear in 7070 nginx and the log appears in 8080 nginx.
I don’t know why the request goes to 8080 nginx.
How can I send the request to 7070 nginx?