Nginx Proxy Pass dont acceppts user & password - nginx

i need to proxy pass one URL from my internal network, that looks like this here:
http://<user><passwd><ipaddress>:<port>/cgi-bin/mjpg/video.cgi?channel=1&subtype=1
But this configuration always ends up in an error:
nginx: [emerg] invalid port in upstream "user:passwd#192.168.133.122:8080/cgi-bin/mjpg/video.cgi?channel=1&subtype=1" in /etc/nginx/sites-enabled/default:15
nginx: configuration file /etc/nginx/nginx.conf test failed
The only working way i get nginx to work is this one:
server {
listen 80;
root /var/www/html;
index index.php index.html index.htm;
location /video.cgi {
proxy_pass http://192.168.133.122:8080/cgi-bin/mjpg/video.cgi?channel=1&subtype=1;
}
}
But in this configuration the User and the Password are not included. Is there a way to get user&password also in the proxy_pass?
thanks
Franz

Related

nginx: 502 bad gateway if /index.html is not in URL

i don't understand what i'm doing wrong so i hope somebody can help :)
When i access http://10.0.0.54/index.html i get the right page but if i try to access http://10.0.0.54 instead of showing the index file it redirects me to https://10.0.0.54 showing error 502 bad gateway.
This is the configuration /etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/salvaderi;
index index.html;
server_name _;
location ~ /.well-known/acme-challenge {
allow all;
root /var/www/html/salvaderi;
}
location / {
root /var/www/html/salvaderi;
index index.html;
}
}
I am running nginx 1.18.0 on ubuntu 22.04
i tried changing parameters inside location /{} but i always get the same result. I also changed the root directory and made sure permission where set right. Searching on for the solution i saw other people having problems about PHP and FastCGI but i am not using it.
Your configuration about to be right.
Possible there is some kind of proxy or load-balancer is placed between you and nginx you configuring since you got redirect to HTTPS whether there is no any redirection instructions in your config and, in the same time, there is no listen 443 ssl in config, but you still got response on HTTPS request.
I'd check next:
Is 10.0.0.54 in fact IP of your server?
Is there any return 301, return 302 or rewrite instructions in your nginx config (the better
way is to dump config with nginx -T command and look over).
Didn't
you previously have configured some redirects that may have been
cached by your web client previously? Try to send GET request with
curl instead of web browser (if browser been used for tests).

How does nginx know my servers url adress?

I installed nginx using sudo apt-get install nginx.
Now this allows me to go to my_ip:port and it allows me to visit the website.
Yet, i can also do my_url:port and it will also direct me to the website.
How can nginx know my_url when I have not told it my_url anymore?
I was running Apache before, can that explain it?
Nginx was able to load via the fqdn my_url:port even though you haven't added my_url in the nginx config because config default_server (usually there by default) was specified.
default_server parameter specifies which block should serve a request if the server_name requested does not match any of the available server blocks:
For example
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}
Nginx doesn't need it (at least, not yet). Your web browser looks up my_url in the DNS, and then uses my_ip (from DNS) :port (which you entered in your browser) to connect to Nginx.
Your Nginx is probably only configured with one site, which means any connection to it - regardless of whether it is by IP or by domain name - causes Nginx to serve that site. You can change this by going into your Nginx configuration files and setting (or changing) the value of the server_name parameter, for example:
server { # You already have a server block somewhere in the config file
listen 80; # Or 443, if you've enabled SSL
server_name example.com www.example.com; # Add (or change) this line to the list of addresses you want to answer to

HTTP user agent block nginx restart fail

I trying to paste the following on my
nginx version: nginx/1.4.6 (Ubuntu)
server {
server_name www.example.com example.com;
access_log /var/www/logs/example_access.log;
error_log /var/www/logs/example_error.log;
root /var/www/html;
# case insensitive matching
if ($http_user_agent ~* (netcrawl|npbot|malicious|wget)) {
return 403;
}
location / {
index index.html index.htm index.php;
}
}
service nginx reload && service nginx restart
I did the following at another server
wget "http://mymainserver.com/myfile.html"
It still able to 200 ok fetch the file.
Any idea what do i do wrong.
Thanks!
Missing "}" in your config file
nginx: [emerg] unexpected end of file, expecting "}"
As a result,
nginx reload fails and service nginx restart is not even not called.
OR
server_name in your config file mismatches hostname used in wget => nginx skips your location

Nginx unknown directive "proxy_pass"

I'm having a problem with nginx configuration.
When I set the configuration like this:
server {
server_name redmine;
listen 80;
location / {
proxy_pass http://172.16.0.70:33000;
}
}
I get this error nginx: [emerg] unknown directive "proxy_pass".
My nginx version is nginx/1.8.0.
Someone know what i'm missing or what i'm doing wrong? Thanks.
Seems that module ngx_http_proxy_module is not installed
Run nginx -V to view how nginx is configured. If it is configured with option --without-http_proxy_module than nginx doesn't have proxy module and should be recompiled.

When do we need to use http block in nginx config file?

I am reading nginx beginner's tutorial, on the section Serving Static Content they have
http {
server {
}
}
but when I add an http block I get the error
[emerg] "http" directive is not allowed here …
When I remove the http block and change the conf file to this, it works fine:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/example.com/html;
index index.html index.htm;
# make site accessible from http://localhost/
server_name localhost
location / {
try_files $uri $uri/ /index.html;
}
I suspect that I am missing something simple, but why do they use http to serve static files?
Your doing fine. I guess you are editing /etc/nginx/sites-enabled/default (or the linked file at /etc/nginx/sites-available/default.
This is the standard nginx set up. It is configured with /etc/nginx/nginx.conf which contains the http {} statement. This in turn contains an "include /etc/nginx/sites-enabled/*" line to include your file above with server{ } clause in it.
Note that if you are using an editor that creates a backup file, you must modify the include statement to exclude the backup files, or you will get some "interesting" errors! My line is
include /etc/nginx/sites-enabled/*[a-zA-Z]
which will not pick up backup files ending in a tilde. YMMV.

Resources