nginx

4 readers
1 users here now

The nginx community on Reddit. Reddit gives you the best of the internet in one place.

founded 1 year ago
MODERATORS
101
 
 
The original post: /r/nginx by /u/Adorable-Novel-3953 on 2024-07-24 13:17:39.

Trying to run /usr/sbin/nginx -t -q on shell also times out.. last entries in the error.log are

2024/07/24 03:58:23 [crit] 131222#131222: *1329230 SSL_do_handshake() failed (SSL: error:0A00006C:SSL routines::bad key share) while SSL handshaking, client: xxx.xxx.xxx.xxx, server: 0.0.0.0:443
2024/07/24 03:58:57 [crit] 131222#131222: *1329755 connect() to unix:/does/not/exist failed (2: No such file or directory) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxxxxxxxx.xxxx.xxxx, request: "PUT /testing-put.txt HTTP/1.1", upstream: "fastcgi://unix:/does/not/exist:", host: "xxxxxxxxx.xxxx.xxxx"
2024/07/24 03:59:03 [crit] 131222#131222: *1329869 connect() to unix:/does/not/exist failed (2: No such file or directory) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxxxxxxxx.xxxx.xxxx, request: "GET /testing-put.txt HTTP/1.1", upstream: "fastcgi://unix:/does/not/exist:", host: "xxxxxxxxx.xxxx.xxxx"
2024/07/24 04:00:06 [alert] 131222#131222: *1330781 open socket #293 left in connection 5
2024/07/24 04:00:06 [alert] 131222#131222: *1330782 open socket #294 left in connection 48
2024/07/24 04:00:06 [alert] 131222#131222: *1330099 open socket #67 left in connection 79
2024/07/24 04:00:06 [alert] 131222#131222: *1330780 open socket #292 left in connection 93
2024/07/24 04:00:06 [alert] 131222#131222: *1330253 open socket #280 left in connection 118
2024/07/24 04:00:06 [alert] 131222#131222: *1330778 open socket #282 left in connection 155
2024/07/24 04:00:06 [alert] 131222#131222: *1330783 open socket #296 left in connection 161
2024/07/24 04:00:06 [alert] 131222#131222: *1330773 open socket #268 left in connection 176
2024/07/24 04:00:06 [alert] 131222#131222: *1330525 open socket #243 left in connection 185
2024/07/24 04:00:06 [alert] 131222#131222: *1330785 open socket #298 left in connection 193
2024/07/24 04:00:06 [alert] 131222#131222: *1330779 open socket #285 left in connection 201
2024/07/24 04:00:06 [alert] 131222#131222: *1330772 open socket #263 left in connection 214
2024/07/24 04:00:06 [alert] 131222#131222: *1330770 open socket #248 left in connection 230
2024/07/24 04:00:06 [alert] 131222#131222: *1330775 open socket #273 left in connection 231
2024/07/24 04:00:06 [alert] 131222#131222: *1330767 open socket #217 left in connection 235
2024/07/24 04:00:06 [alert] 131222#131222: *1330774 open socket #271 left in connection 244
2024/07/24 04:00:06 [alert] 131222#131222: *1330776 open socket #275 left in connection 309
2024/07/24 04:00:06 [alert] 131222#131222: *1330771 open socket #253 left in connection 316
2024/07/24 04:00:06 [alert] 131222#131222: *1330763 open socket #209 left in connection 319
2024/07/24 04:00:06 [alert] 131222#131222: *1330768 open socket #237 left in connection 346
2024/07/24 04:00:06 [alert] 131222#131222: *1330762 open socket #155 left in connection 367
2024/07/24 04:00:06 [alert] 131222#131222: *1330766 open socket #23 left in connection 383
2024/07/24 04:00:06 [alert] 131222#131222: *1330777 open socket #279 left in connection 392
2024/07/24 04:00:06 [alert] 131222#131222: *1330769 open socket #245 left in connection 395
2024/07/24 04:00:06 [alert] 131222#131222: *1330784 open socket #297 left in connection 428
2024/07/24 04:00:06 [alert] 131222#131222: aborting

Tried rebooting server as well.. it was working just fine till a few hours ago.. what could be going on here.. any help/pointers will be greatly appreciated..

102
 
 
The original post: /r/nginx by /u/bagelwoof on 2024-07-24 02:42:08.

I have two questions. First question:

I have an instance of NGINX running on a PI that I'm using to reverse proxy lots of things that are running on a variety of different bits and pieces of computer hardware...

I would like to have the connections between NGINX and whatever it's proxying be over https (TLS?) but I'm not sure how to do that.

I think I need to

  1. set up a minimal CA/PKI
  2. install and trust the root CA cert on the NGINX host
  3. Issue certs for each of the hosts using my root/CA cert
  4. install the host certs on the actual hosts

Is that right? If not, how should I do this?

Second question:

I feel really dumb not knowing if I should be asking about upstream or downstream in this question... I think if I knew the answer to this question, I could do the usual search engine tap dance and have usable answers. I admint that I'm totally cosplaying a sysadmin.

say I have The Internets -> My Router -> NGINX -> A Thing on a Pi

from the perspective of NGINX, is my thing on a Pi upstream or downstream? Assuming all the users are somewhere toward the Internet?

Thanks!

103
 
 
The original post: /r/nginx by /u/Tap_Regular233 on 2024-07-18 06:35:57.

I keep getting 'Unable to connect to the host / port' error whenever I try to access certain websites. Tried troubleshooting with different browsers and clearing cache, but no luck.

104
 
 
The original post: /r/nginx by /u/MRgabbar on 2024-07-17 15:36:48.

Seems to be working on Chrome/Chromium/WebKit just fine, but Firefox either times out or just says security risk when using the www.

This is my current configuration:

server {

listen 80;

server_name example.com www.example.com;

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

return 301 https://example.com$request_uri;

}

# Redirect all HTTP requests to HTTPS

return 301 https://$host$request_uri;

}

server {

listen 443 ssl;

server_name example.com;

ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;

ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

root /var/www/example.com;

index index.html;

location / {

try_files $uri /index.html;

}

}

Anything wrong with it???

105
 
 
The original post: /r/nginx by /u/Host-Total on 2024-07-17 12:35:34.

I deployed an nginx docker application locally and it works fine

when I deploy same application on my website pipeline

Instead I get

Uncaught SyntaxError: Unexpected token '<' (at _ssgManifest.js:1:1)

All my js scripts inside are retuned as html

what might be wrong please help

106
 
 
The original post: /r/nginx by /u/suddenmedics on 2024-07-17 02:18:03.

I've been tinkering with my Nginx server setup recently and stumbled upon a neat trick to prevent those pesky requests with undefined server names from messing things up. It's all about tightening security and keeping things smooth. Any Nginx pros out there have other cool tricks up their sleeves?

107
 
 
The original post: /r/nginx by /u/Board_Pristine757 on 2024-07-17 01:11:13.

I'm struggling with my NGINX setup and could really use some advice. I'm trying to configure reverse proxy for multiple backend services, but I keep encountering 502 errors. I've checked my configurations, but can't seem to pinpoint the issue. Any ideas on troubleshooting this? Thanks!

108
 
 
The original post: /r/nginx by /u/Ruben-Costa on 2024-07-16 20:55:06.

Here is the config that is stored on /etc/nginx/conf.d. Below are some logs that may or not be useful

server {
    listen 80;
    server_name localhost;

    # Improved logging
    access_log /var/log/nginx/access.log main;
    error_log /var/log/nginx/error.log warn;

    location ~* \.(eot|ttf|woff|woff2)$ {
        add_header Access-Control-Allow-Origin *;
    }

    location /api/auth/ {
        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' '*' always;
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
            add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
            add_header 'Access-Control-Max-Age' 1728000 always;
            add_header 'Content-Length' 0;
            add_header 'Content-Type' 'text/plain; charset=utf-8';
            return 204;
        }

        proxy_pass http://auth:3000/api/auth/;
        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;

        # Cache headers (adjust caching duration as needed)
        add_header 'Cache-Control' 'public, max-age=3600' always;

        # Add CORS headers
        add_header 'Access-Control-Allow-Origin' '*' always;
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
    }

    location /api/data/ {
        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' '*' always;
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
            add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
            add_header 'Access-Control-Max-Age' 1728000 always;
            add_header 'Content-Length' 0;
            add_header 'Content-Type' 'text/plain; charset=utf-8';
            return 204;
        }

        proxy_pass http://data:3000/api/data/;
        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;

        # Cache headers (adjust caching duration as needed)
        add_header 'Cache-Control' 'public, max-age=3600' always;

        # Add CORS headers
        add_header 'Access-Control-Allow-Origin' '*' always;
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
    }
}

This request is canceled due to CORS errors (browser)

192.168.65.1 - - [14/Jul/2024:14:38:09 +0000] "OPTIONS /api/auth/signin HTTP/1.1" 204 0 "http://localhost:19006/" "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604.1" "-"

Thank you in advance

109
 
 
The original post: /r/nginx by /u/musbur on 2024-07-16 19:15:14.

Hi all, I'm completely stumped by a configuration conundrum. I'm running a WSGI application under gunicorn on a UNIX socket and I'm trying to proxy to it but not from the root location. Problem is, all tutorials and documentation show only how to proxy the "/" location bot not others. I've pruned my nginx config down to this, which works:

server {
    include uwsgi_params;
    location / {
        proxy_pass http://unix:/run/gunicorn/test.sock;
    }
}

However, I don't want the WSGI app to live at root but at /test. But when I replace location / by location /test or location /test/, I always get a 404 error (directly from nginx not from the WSGI app).

How is this done correctly?

110
1
help (zerobytes.monster)
submitted 4 months ago by [email protected] to c/[email protected]
 
 
The original post: /r/nginx by /u/zombieskater236 on 2024-07-16 05:22:09.

I accidentally searched up pwned.com meaning to search up something else. it says the web server is successfully installed. i’ve cleared my cache and deleted the data for the website on chrome. from reading some posts it seems like it’s fine but just wanted to confirm that i’ve gotten rid of any potential download regarding this, or where i could check. (im not using a cloud pc, just chrome and searched that link, no pop ups or anything)

111
 
 
The original post: /r/nginx by /u/Historical_Ad4384 on 2024-07-15 14:49:39.

Hi,

I have a custom log format that I define within the http block of my nginx config file

How do I tell NGINX to use this custom log format?

Here is the snippet of the custom log format definition:

    log_format json_combined escape=json
    '{'
        '"time_local":"$time_local",'
        '"remote_addr":"$remote_addr",'
        '"remote_user":"$remote_user",'
        '"request":"$request",'
        '"status": "$status",'
        '"body_bytes_sent":"$body_bytes_sent",'
        '"request_time":"$request_time",'
        '"http_referrer":"$http_referer",'
        '"http_user_agent":"$http_user_agent"'
    '}';

112
 
 
The original post: /r/nginx by /u/cmt00 on 2024-07-14 21:02:09.
113
 
 
The original post: /r/nginx by /u/YogurtclosetDouble50 on 2024-07-14 18:15:20.

Hi all, have stepped back into development in my free time after leaving the career over a decade ago. Back then the stuff I was working on didn’t use webhooks in any way so I’m totally unfamiliar with them.

I’ve been reading various articles online but not sure if I understand how they would work for my application.

I am currently running an Apache server (although I’m also running it on nginx to get familiar with that server as well). PHP backend serving html which is then interacted with by the user with a fair bit of jquery (planning on moving to vue once I’ve got my head round it).

The basic idea is that the page loads up a bunch of appointments and displays them as a grid. This content is pulled from a REST API from a patient management cloud system.

The page refreshes every 10 minutes as the bookings change regularly but not enough to warrant constant updates

What would be useful though is the api that the patient management system has also has webhooks that can be used when a diagnostic imaging request is updated or created (diagnosticimagingworklist_id). The docs for the system state “each of the hooks can have a different (or same) URL address, to which the system sends the hook when triggered by the event”. This is the one bit of info that would be hugely helpful if any changes made were apparent on my system immediately, rather than waiting for a refresh.

So from what I understand, some of the config needs to be done on the management system. That’s fine. But where do the urls come from? Is this something I need to configure in Apache/Nginx? And when these communicate, how is that then reflected on the front end?

I realise these may be quite basic questions but nothing I’ve read so far has got the concept into my head as to how this would work for my setup.

114
 
 
The original post: /r/nginx by /u/Aslimedr_wsnear on 2024-07-13 13:33:19.

I have NGINX set up and I can access my internal apps by going to a specific url (duckdns in my case). so if I go to my internal URL site it will provide me access to my internal page.

but if I also go into the web browser and type in the internal IP address of that same page instead, it works, obviously HTTP without an SSL certificate.

can NGINX redirect traffic so if someone types in 192.168... it will instead direct them to the URL instead?

115
 
 
The original post: /r/nginx by /u/peter_gil on 2024-07-13 11:39:44.

Hello swarm intelligence, I'd like to install older versions of nginx between version 1.25.0-1.26.1 on my ubuntu machine. apt only offers version 1.26.1 and 1.26.0. nginx.org only offers legacy versions from 1.24 and below Do you know where I can find older versions? The reason I want to install it is a reseach project

116
 
 
The original post: /r/nginx by /u/Aslimedr_wsnear on 2024-07-13 02:03:28.

I added my internal IP to duckdns (192.168.x.x) - if I go into NGINX Proxy Manager and add the SSL Certificate, when I try to connect using a DNS Challenge I get this error:

Internal error

CommandError: usage: 
  certbot [SUBCOMMAND] [options] [-d DOMAIN] [-d DOMAIN] ...
Certbot can obtain and install HTTPS/TLS/SSL certificates.  By default,
it will attempt to use a webserver both for obtaining and installing the
certificate. 
certbot: error: unrecognized arguments: --dns-duckdns-credentials /etc/letsencrypt/credentials/credentials-35 --dns-duckdns-no-txt-restore
    at /app/lib/utils.js:16:13
    at ChildProcess.exithandler (node:child_process:410:5)
    at ChildProcess.emit (node:events:513:28)
    at maybeClose (node:internal/child_process:1100:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5)

I went into my port forwarding and I added

Port: 80,443

Forward IP: IP address of my NGINX server

Forward Port: 80,443

But it still doesn't work. I'm not entirely sure what I am doing wrong.

117
 
 
The original post: /r/nginx by /u/Trbutler13 on 2024-07-13 00:04:37.

I have NGINX configured on two LXC containers — one vanilla Debian and one AlmaLinux — trying to meet or exceed the performance of my older server running a cPanel managed installation of NGINX as a reverse proxy. However, my vanilla installations, whether with NGINX as a direct web server or caching reverse proxy in front of Apache, clocks in 54% slower than my older cPanel/WHM server’s NGINX implementation. This is despite the actual new server being as good or better hardware wise in every way over the one it is replacing.

Using ab -n 10000 -c 100 -k -H "Accept-Encoding: gzip, deflate" -H "User-Agent: BenchmarkTool" https://———————.com/ to benchmark my configuration, requesting the most basic of pages on an AlmaLinux or Debian container takes 75ms; on the older cPanel/AlmaLinux install it takes just 46ms. In both cases, all but 1-2ms of that is “processing” according to ab.

Thinking maybe something was amiss with the machine or LXC, I tried installing NGINX directly on the containers' host machine (Debian/Proxmox) to see if that would show the containers to be the source of the substantial overhead. I also installed NGINX on a separate VPS I have from a cloud provider. In both cases, I still hit the same approximate performance barrier (~ 70ms processing time for a tiny webpage), with the containers maybe adding 3ms or so at worst. None of the attempts comes close to the cPanel server's ~ 40ms processing time.

I have a more convoluted configuration attempt with every directive I could throw at it to try to optimize things, attempting to distill some of the inscrutable layers of settings on the cPanel server to try to find the “magic” one that provides the better performance, but the result comes out the same as this simpler configuration:

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024; #Also tried 2048
}

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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

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

    server {
        server_name  ---------------.com _;
        root         /usr/share/nginx/html;

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

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

    listen [::]:443 ssl http2 ipv6only=on; # managed by Certbot
    listen 443 http2 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/t-------------.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/-------------.com/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

}

I’ve run Geekbench on both servers and the newer one’s containers perform faster than the old one, just as I’d expect. I’ve run various disk I/O tests and found the two servers essentially indistinguishable on that count, both running on a reasonably fast SSD of equal speed.

When ab is running a 10,000 connection test, the container never shows more than 5% CPU usage.

Is there anything obvious I’m missing that might help get the new server’s NGINX performance down to the ~ 40ms processing range on a simple page, given that I know such is a realistic goal based on the other server’s performance?

(To be clear, since I know cPanel is frowned upon on here, I am not asking about how to configure cPanel; the new server is not running a control panel.)

Update: I tried using wrk -t12 -c400 -d30s https://-----.com and using wrk the new server significantly outperforms the old server. Using NGINX as a reverse proxy on both, below are the results. So, perhaps there's something with ab rather than my server?

root@juniper:/etc/nginx/sites-enabled# wrk -t12 -c400 -d30s https://---newserver----.com/testing.html
Running 30s test @ https://---newserver----.com/testing.html
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     4.11ms    6.34ms 231.47ms   87.84%
    Req/Sec    11.04k     4.50k   26.31k    67.78%
  3930823 requests in 30.07s, 1.11GB read
Requests/sec: 130701.72
Transfer/sec:     37.64MB

root@juniper:/etc/nginx/sites-enabled# wrk -t12 -c400 -d30s https://---oldserver---.com/testing.html
Running 30s test @ https://---oldserver---.com/testing.html
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    70.01ms   34.05ms 358.01ms   74.22%
    Req/Sec   477.03    174.44     1.03k    68.58%
  169995 requests in 30.09s, 33.88MB read
Requests/sec:   5649.18
Transfer/sec:      1.13MB

118
 
 
The original post: /r/nginx by /u/allnnde on 2024-07-12 22:23:33.

Hi, I hope you can help me

I currently have a system consisting of:

I am using a backend in .net and a frontend in react.

when I raise everything in a container I have the backend container and the nginx container which has in the html folder the react files.

now I try to add in the nginx configuration the path to see the swagger of the backend, but it is always throwing me an error.

the last error that I have thrown is end of the stream or a document separator is expected

nginx.conf:

events{
    worker_connections 768;
}

http{
    server{
        listen 80 default_server;
        listen [::]:80 default_server;
        
        server_name doctaonline.com, www.doctaonline.com;        
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        include /etc/nginx/mime.types;
        
        try_files $uri /index.html =404;
        location / {
            try_files $uri $uri/ /index.html;
        }
        location /api {           
           proxy_set_header Host $host;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_pass http://webapi:80;
        }
        location /docs {           
           proxy_set_header Host $host;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_pass http://webapi:80/swagger/index.html;
        }

        location /health {           
           proxy_set_header Host $host;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_pass http://webapi:80/health;
        }
    }
}

startup.cs

        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);
            var corsPolicyName = "_corsPolicy";

            builder.Host.UseFileLogging(builder.Configuration);

            // Add services to the container.
            builder.Services.AddControllers()
                .AddJsonOptions(opt => opt.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.IgnoreCycles);

            // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
            builder.Services.AddEndpointsApiExplorer();
            builder.Services.AddSwaggerGen(option =>
            {
                option.SwaggerDoc("v1", new OpenApiInfo { Title = "Docta API", Version = "v1" });
                option.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    In = ParameterLocation.Header,
                    Description = "Please enter a valid token",
                    Name = "Authorization",
                    Type = SecuritySchemeType.Http,
                    BearerFormat = "JWT",
                    Scheme = "Bearer"
                });
                option.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                            {
                                new OpenApiSecurityScheme
                                {
                                    Reference = new OpenApiReference
                                    {
                                        Type=ReferenceType.SecurityScheme,
                                        Id="Bearer"
                                    }
                                },
                                new string[]{}
                            }
                        });
            });
            builder.Services.AddHttpContextAccessor();
            builder.Services.Configure<ApiBehaviorOptions>(options =>
            {
                options.SuppressModelStateInvalidFilter = true;
            });

            builder.Services.AddCors(opt =>
            {
                opt.AddPolicy(corsPolicyName, plc => plc.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
            });

            builder.Services.AddAuthorization()
                .AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                .AddJwtBearer(options =>
                {
                    options.TokenValidationParameters = new TokenValidationParameters
                    {
                        ValidateIssuer = true,
                        ValidateAudience = false,
                        ValidateLifetime = true,
                        ValidateIssuerSigningKey = true,
                        ValidIssuer = builder.Configuration["Auth:Issuer"],
                        IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Auth:Key"]))
                    };
                });

            //Add custom Serivces
            builder.Services.RegisterDbContext(builder.Configuration);
            builder.Services.RegisterRepositories();
            builder.Services.RegisterServices();
            builder.Services.RegisterHelpers();
            builder.Services.RegisterAutomapper();
            builder.Services.RegisterValidators();

            builder.Services.AddHealthChecks()
                .AddCheck<EnviromentHealthCheck>("Environment")
                .AddCheck<VersionHealthCheck>("Version")
                .AddCheck<PaymentUrlHealthCheck>("PaymentURL")
                .AddNpgSql(builder.Configuration.GetConnectionString("ELEARMING"));

            var app = builder.Build();

            // Configure the HTTP request pipeline.

            app.UseSwagger();
            app.UseSwaggerUI();

            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });

            //app.UseHttpsRedirection();

            app.UseCors(corsPolicyName);

            app.UseRouting();

            app.UseDefaultFiles();
            app.UseStaticFiles(new StaticFileOptions
            {
                ServeUnknownFileTypes = true
            });

            app.UseAuthorization();

            app.UseHealthChecks("/health", new HealthCheckOptions()
            {
                Predicate = _ => true,
                ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
            });

            app.MapControllers();
            app.MapHealthChecks("/health");

            app.Run();
        }
    }

Soory for my english

119
 
 
The original post: /r/nginx by /u/LavaBoy5890 on 2024-07-12 20:26:33.

I have my React project hosted on EC2 with Nginx as the proxy. I also have GitHub actions set up, which seems to work. The main problem is that I can't seem to serve images. I can serve images locally (I use Vite for my local dev server if that helps) but when the project is hosted, it only serves everything except pictures. I can't seem to serve .jpg or .svg, even though these are both configured correctly in mime.types and mime.types is included in nginx.conf. My config file in sites-enabled looks like this:

https://preview.redd.it/necggiur55cd1.png?width=1093&format=png&auto=webp&s=629e7ca402bd8bb289b1f883f27731538bc70baf

I am not sure if I need both location contexts since the React project is referring to the image's correct location in server and should already be pulling the image from there, but I figured I would try. I'm just not really sure what's wrong; when I go into the console there are no errors. I've ran nginx -t and looked at error files; nothing. In the dev tools under Network I see that my picture name is present; it's just not showing up on the page (instead I get a default icon). Notably under the Network tab in dev tools it's saying that my pic has a type of "text/html" rather than "jpeg". If anyone could help I'd appreciate it.

120
 
 
The original post: /r/nginx by /u/Tap_Regular233 on 2024-07-12 07:17:25.

I'm curious about the key differences between Apache and Nginx. I know Apache is super customizable with modules, but I've heard Nginx is better with handling a ton of concurrent connections. Anyone have insights on when to choose one over the other?

How do they stack up in terms of performance and ease of use?

121
 
 
The original post: /r/nginx by /u/ThornlessCactus on 2024-07-12 04:53:44.

Hi,

Is it possible to do the whole thing in just nginx? I know I can do it easily in nodejs or python or c/++., but I have a more contrived application written in some interpreted slow language that i would like to rewrite in C and work as a glue-code nginx module, but it would need to access multiple server blocks with different ports and protocols.

Thanks.

Edit: for clarity,

I want one browser webapp to send data by http and another browser webapp to receive the same data by websocket. My actual requirement is a fair bit more complex than this.

122
 
 
The original post: /r/nginx by /u/Bananawamajama on 2024-07-10 22:59:34.

I have a website thats just a single html page.

I installed nginx and its working so if I type my computers ip address in chrome on my phone the site comes up when Im on wifi.

How do I configure this to make it so that I can see this page from when Im not at home? I cant input 192.168.XX.XX. If I type my public IP address that doesnt work either. I figure I need to do something extra to enable it maybe?

123
 
 
The original post: /r/nginx by /u/Top_Squirrel2052 on 2024-07-10 09:37:00.

Hello everyone!

I am relatively new to NGINX and I am currently setting up a server to host my React Single Page Application. I've encountered a problem with the mirroring of requests, specifically around duplications that I can't seem to resolve.

My goal is to mirror each request to a monitoring service running on another port (8080). This service needs to capture the IP of clients visiting my website. No matter which path / route a client visits, the request should be mirrored ONCE to the service on port 8080.

I've set up the NGINX mirror directive to mirror requests to my monitoring service. However, when someone accesses the root path '/', the request is mirrored TWICE instead of once. Accessing other paths / routes mirrors the request correctly only once. This duplication only occurs at the root path. I think it is because of some internal redirection from '/' to '/index.html'.

Here is my current NGINX configuration:

server {
    listen 80;
    root /var/www/html/dist;
    index index.html;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log debug;

    location / {
        mirror /notifier;
        try_files $uri $uri/ /index.html;
    }

    location = /notifier {
        internal;
        proxy_pass http://localhost:8080/;
    }

    location ~* \.(css|js|jpg|jpeg|gif|png|ico|svg|woff|woff2|ttf|eot)$ {
        try_files $uri =404;
    }
}

nginx version: 1.18.0

If you guys need any more information, feel free to ask!

124
1
Rust Rewrite? (zerobytes.monster)
submitted 4 months ago by [email protected] to c/[email protected]
 
 
The original post: /r/nginx by /u/electriksquirrel on 2024-07-08 22:44:47.

Does anyone know of or has considered an Nginx rewrite in Rust? Part of the motivation is that it has a great core but feature-wise is slow and gated with Nginx+. A community-driven implementation would allow for more feature development. I'm not aware of a popular high-performance proxy written in a memory-safe language.

Nginx - C

HAProxy - C

Envoy - C++

Apache Httpd - C

Varnish - C

Angie (Nginx fork by Nginx folks) - C

Caddy is written in Go but idk if it would be considered performance-oriented (rather is more UX-oriented).

There's some kubernetes proxies written in Rust but they're very application-specific e.g. Linkerd.

125
 
 
The original post: /r/nginx by /u/abhishek_tomar on 2024-07-08 17:33:00.

Hello, Can someone please help with this.

I have deploy my Angular app on K8s and everthing is works on my local but when i deploy the same on K8s my app is working first page is loading but when i hit any button its not redirecting on next page looks Nginx issue.

view more: ‹ prev next ›