Quantcast
Channel: Nginx Forum - How to...
Viewing all 2931 articles
Browse latest View live

Sub_filter: replacing a string containing $ (no replies)

$
0
0
Nginx sub_filter syntax: sub_filter string replacement;

A variable in Nginx is set using the operand $: set $a 'Hello World';

When a $ is present in sub_filter String but not a variable, Nginx will not allow the String e.g.

sub_filter 'data-ng-click="$ctrl.goto 'onclick="location.href=';

I am sure there is a "work around" so that $ctrl is not seen as a variable and just part of the String to be replaced?

Any help would be appreciated

Install http_charset_module (1 reply)

$
0
0
Good Day;

How do I install http_charset_module on an Nginx installed via apt install.

A couple of read up does not tell who and we wish to use these facility on our proxies.

Regards;

Abson

Nginx rewrite urls to match proxy address (no replies)

$
0
0
I am running a wordpress docker container , the site is accessible through host machines port 8000 , if go to localhost:8000 boom i get to see my wordpress site.

It's boring to always type localhost:8000 to see my website, so i decided to commission nginx as a reverse proxy for my site. I've set up a virtual host in nginx that has the name proxy.site , i can now access by wordpress site by visiting http://proxy.site.

Up until this point, we are doing great, when http://proxy.site opens up, i can see a list of my blog posts, lets say i want to read my latest blog post about COVID-19 , when i click on the link, ohohohoho it opens up as http://localhost:8000/posts/covid19

I want it to open with the proxy url as in http://proxy.site/posts/covid19 , i need to whole site to be accessible through the http://proxy.site site name,

I need nginx to rewrite all my links in localhost:8000/* to proxy.site/* , no body loves typing ports when accessing a blog,

Here is how my nginx conf file looks like

server {
listen 80;
listen [::]:80;

root /var/www/proxy.site/html;
index index.html index.htm index.nginx-debian.html;

server_name proxy.site www.proxy.site;

location / {
proxy_pass http://localhost:8000;
#proxy_set_header HOST $host;
#proxy_redirect http://localhost:8000/ http://proxy.site/ ;
#try_files $uri $uri/ =404;
}
}

How do i achieve rewrite all urls in the proxied site with my custom host name ?

How to repace domain with IP (no replies)

$
0
0
I need to pass an IP rather than any taken FQDN to my back-end service. For example:
URL in browser is https://test.domain.com or https://test1.domain.com
I redirected port 443 to http://10.100.0.20:2020

Now, I want to change both domain, above, to the10.100.0.20 before they used by back-end service so that the back-end service work by the IP address in it's configuration not domains.

Is it possible?

First time - reverse proxy on oracle linux (1 reply)

$
0
0
Hello ,
as I understadn I can use nginx reverse proxy in order to give people access to my local network from the web.
so if my proxy IP is 85.159.4.4 and I want them to be able to enter to devices on 172.16.5/24 -- I can do this
first - is this true?

I setup nginx ,
added a simple link on the /usr/share/nginx/html/index.html
<a href="http://172.16.5.26">Local Device1<a>.</br>.</p>

from the server I have ping and can access to it
but when I connect to the server from the internet - I can't reach it .

what do I need to do in order to make this work?

Thanks ,

give access after proxy_pass (no replies)

$
0
0
Hello
I have this simple setting :
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location /FirstPage.html {
#proxy_set_header Host $http_host$request_uri;
proxy_pass http://172.16.254.120/;
#proxy_read_timeout 120s;
#access_log on;

}

location /error.html {
internal;
}

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

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


now , when I enter FirstPage.html - he redirect me to 172.16.254.120
but when I want to enter other pages after it - I get error message
"The pgae you are looking for is not found "
how to fix this?
what I need to add to allow me to work in 172.16.254.120?

Thanks ,

Cannot password protect Nginx subdirectory (no replies)

$
0
0
I'm trying to set a username/password protection on an Nginx subdirectory, but I'm still able to access the subdirectory without supplying credentials.

The Nginx is running on an AWS CentOS 7 instance.
My default.conf is:

[centos@ip-172-31-35-133 nginx]$ cat /etc/nginx/conf.d/default.conf
server {

location /rbarark_test {
satisfy any;

root /usr/share/nginx/html;
index index.html index.htm;
auth_basic "Restricted area - This system is for the use of authorized users only!";
auth_basic_user_file /etc/nginx/.htpasswd;
}
}
[centos@ip-172-31-35-133 nginx]$

I added a username/password entry to .htpasswd:

[centos@ip-172-31-35-133 nginx]$ ls -ls /etc/nginx/.htpasswd
4 -rw-r--r--. 1 root root 45 Mar 24 23:39 /etc/nginx/.htpasswd
[centos@ip-172-31-35-133 nginx]$

And all the web-site files are at:

[centos@ip-172-31-35-133 nginx]$ ls /usr/share/nginx/html/rbarak_test/en/
amazon-dynamodb-audit-integration-guide.html cockroachdb-integration-guide.html jsonar--solutions-for-agentless-oracle-db-auditing.html os-auditing-solution.html
amazon-redshift-audit-integration-guide.html cockroach-integration-guide.html mongodb-atlas-integration-guide-157488.html params.manifest
aws-auditing-initial-setup.html db-auditing-solution.html mongodb-atlas-integration-guide.html postgresql-integration-guides.html
aws-integration-guides.html dispatcher-rdbms-oracle-prerequisites.html mongodb-integration-guides.html snowflake-integration-guide.html
aws-rds-audit-integration-guide-156347.html glossary.html ms-sql-integration-guides.html sso-with-pingfederate.html
aws-rds-audit-integration-guide.html image mysql-integration-guides.html teradata-integration-guide.html
aws-rds-integration-guide.html index-en.html oracle-audit-vault.html toc-en.html
cloudera-integration-guides.html js oracle-integration-guides.html unified-auditing-solution.html
[centos@ip-172-31-35-133 nginx]$


But still, when I connect my browser to http://18.215.232.30/rbarak_test/?lang=en, I'm not challenged to give a username/password.

Can you see what am I doing wrong?

Cannot make expiration date on my images to work (no replies)

$
0
0
I've attached what I have of my config files when I run: docker-compose exec nginx nginx -T

Image is representation of problem that https://gtmetrix.com/ sees on my site.

Served Wordpress file not accessed, seemed cached. Where is it cached? (no replies)

$
0
0
Hello.

I'm new to nginx. I installed it on Fedora 31 workstation, with Wordpress. Nginx and PHP work (php.info works), but Wordpress doesn't. My 1st problem is that when I go with Firefox to mysite.com/wp-admin∕setup-config.php, a Wordpress page is displayed but stat setup-config.php says that setup-config.php has not been accessed recently, even if I had cleared Firefox cache just before. The same is true if I use curl. And I read on the net that Nginx doesn't cache by default... And curl says "Cache-Control: no-cache, must-revalidate, max-age=0". And when I go to mysite.com/wp-admin∕install.php , I get a blank page and stat says the file has not been accessed recently either...
So it seems these files are cached, but by what program? And how to clear the cache?

Thank you for any help.

Nginx and Exchange 2019 (2016) (no replies)

$
0
0
Hi Everyone,

If this topic has been answered before, please let me know.
I unfortunately cannot find any answers for this anywhere.

So I ask you for help and to make me understand what it will require..

Short explanation:
I have a home lab (yes a nerd, but not a programer) running multiple web sites using https.
Today I have a Synology NASm ruling reverseproxy powered by Nginx and Certificates from Lets Encrypt.
Now Synology out of the box does not support exchange traffic, and it is blowing my mind..

So what I rely need is a guide, or how to from someone.
I've installed Nginx on a ubuntu server 18.04.4, Nginx extras is also installed.
I read somewhere that it was needed to get all exchange related traffic to work.
Configuration for Lets Entrypt is not installed at the moment.

And this is where I am.
I'm desperat for some help or answers.

Do Nginx support exchange traffic and what is needed??

On my Synology NAS the reverseproxy failed to connect autodiscover trafific and causes my pc and Mac´s outlook to stop working.

Please help!!

Make multiple subrequests and generate custom response based on the subrequests' response. (no replies)

$
0
0
Hi,

I have a use case where based on the contents of a file (accessed through URI), I need to get the contents of another file (again accessed through URI) and return the contents to the caller.

The exact scenario is this:

URI say http://localhost:80/xxx is invoked -> Based on a request header say X-REQUEST-NAME, formulate the paths of the URI say URI1, make a subrequest to URI1 and download the file say file1 -> Based on the content of the file file1, make another subrequest to a new URI URI2 and download the contents -> return this content to the caller

Is there anyway this can be done?

Regards,
Akshayaa

Nginx default_server catches all. Why? (1 reply)

$
0
0
Hello all,

I have got 2 different URLs that are correctly redirected by Proxy_Pass.
However as soon as I add the default_server (first server below), my 2 URLs are not redirected anymore. They fall into the catch all.
Why is that? I don't understand what is wrong in the default configuration.
Thanks for your help!


# default server for this IP
server{
listen xx.xx.xx.xx:8443 default_server;
server_name _;
return 404;
}

server{
listen xx.xx.xx.xx:8443;
server_name *.staging1.xxxx.com staging1.xxxx.com;

ssl on;
ssl_certificate /etc/letsencrypt/live/mindbelts.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mindbelts.com/privkey.pem;

location / {
proxy_pass http://127.0.0.1:6981;
proxy_set_header Host $host;
}
}


server{
listen xx.xx.xx.xx:8443;
server_name *.staging2.yyyy.com .staging2.yyyy.com

ssl on;
ssl_certificate /etc/letsencrypt/live/mindbelts.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mindbelts.com/privkey.pem;

location / {
proxy_pass http://127.0.0.1:6982;
proxy_set_header Host $host;
}
}

proxy pass m3u8 record (no replies)

$
0
0
Hi to All
I need help. I have some url in m3u8 format, trere is some record file in this url. I Tried proxy_pass with NGINX this url . I check on backend if user have access or not.
My problem is:

When I proxy m3u8 url and try to access from my ios phone all is ok, but if i try on android or vlc i have problem. In m3u8 file there is cuttings of video of files in .ts format, when i start playing on anfroid or VLC player all is work, but if i do STOP and then START again, video is not start from begin time, its start from time when i do STOP. How configure NGINX proxy ? Help me pls
m3u8 file

#EXTM3U
#EXT-X-TARGETDURATION:6
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:2
#EXT-X-PROGRAM-DATE-TIME:2020-04-01T04:14:58Z
#EXTINF:6.000,
dvr-2020/04/01/04/14/58-06000.ts?token=45365c5d4e4f418ce1ed348b7dc1d98a1e15cf02-salt-1742532747-1583757747
#EXTINF:6.000,
dvr-2020/04/01/04/15/04-06000.ts?token=45365c5d4e4f418ce1ed348b7dc1d98a1e15cf02-salt-1742532747-1583757747
#EXTINF:6.000,
dvr-2020/04/01/04/15/10-06000.ts?token=45365c5d4e4f418ce1ed348b7dc1d98a1e15cf02-salt-1742532747-1583757747
#EXTINF:6.000,
dvr-2020/04/01/04/15/16-06000.ts?token=45365c5d4e4f418ce1ed348b7dc1d98a1e15cf02-salt-1742532747-1583757747

nginx
location /watch {
#root html;
#index index.html index.htm;
proxy_pass http://127.0.0.1:8081/api/basic;


http://127.0.0.1:8081/api/basic - backend check user access and if ok redirec to location
location ~* ^/to_proxy/(.*) {
internal;
proxy_pass http://XXX.XXX.XXX.XXX/$1$is_args$args;
add_header Access-Control-Allow-Origin *;


Thank to All so much

auth_basic issue, won't protect full directory (2 replies)

$
0
0
Hello,

I notice a big bug (or is it me) using nginx/1.16.1 (on Arch) and auth_basic which don't protect the whole directory using a simple

location /admin {
auth_basic "Restricted";
auth_basic_user_file /srv/http/admin/.htpasswd;
}

When i go to admin/index.php i got a auth request. But, if i have a admin/test.php file, i can request the file without any auth request.

What am i doing wrong ?
Bye

Last modified header issue (no replies)

$
0
0
We have a feed being generated on our WordPress site every day domain.com/?woocommerce_gpf=google but when doing a curl -I domain.com/?woocommerce_gpf=google the last modified date is a year old and doesn't update when feed get's updated. Any idea how to update the last modified tag for this? It's on a Ubuntu 18.04, Nginx and WordPress/Woocommerce platform.

[Windows 10] Using proxy_pass with OpenVPN? (no replies)

$
0
0
Hey everybody, I've recently set-up an NGINX server on windows 10 with PHP up and running. I want to use proxy pass to go through OpenVPN to prevent my IP address from being leaked. What I was looking to do was to have anything within the root directory be proxy passed through OpenVPN.

I attempted this a few times on my own (since most tutorials were on Ubuntu which for some odd reason never wants to work on my server).

I have no logs to provide sadly, as they would probably be helpful with this.

If anybody has any tips or could help with this I would appreciate it!

Specific redirection by user agent (no replies)

$
0
0
Hello,

I have an issue I can't solve :'(
I would like to generate a redirection by user agent.

I have a physical file : domain.com/stats.xml
I would like to serve this file for ALL except for browser with a specific User Agent (ABC for this example).

So, if User Agent = ABC, user should be redirect to specific-stats.xml
In other case, the file stats.xml has to be served.

I have tried my options. Impossible to find a solution.

Is it possible ?

Thanks
Carlito

Nginx Load Balancer traffic redirection (no replies)

$
0
0
Hi, we have following config :

In the ../conf.d/ folder we have different config files for domains and subdomains. Let's say aaa.conf, bbb.conf, ccc.conf. Nothing unusual in there, they are just "proxy_pass" to corresponding server private IPs depending on URL requested. But here is the thing : we have registered new subdomain ddd.ourdomain.com which have DNS A record pointing to load balancer Public IP and for some reason it redirects the traffic to server IP mentioned in aaa.conf.

We currently do not have ddd.conf in ../conf.d/ and ddd.ourdomain.com is not specified neither in aaa.conf, bbb.conf or ccc.conf. In addition, if I put load balancer public IP in browser like https://1.1.1.1 - it redirects me to server mentioned in aaa.conf as well.

So, here is the question : is that a default Nginx behavior (as I dont see any redirection lines in nginx config and afaik "return" line should not do that) or there is something in the nginx.conf I should look for (or somewhere else)? Snippet from nginx.conf attached

An amazing Nginx website for u people! (no replies)

$
0
0
Hello there! I made an website for WordPress+Nginx related stuff which is really easy for beginners t understand! Do visit it!
Link: https://serverforbeginners.in

tomcat -> nginx write error while streaming lots of data (no replies)

$
0
0
I have an nginx proxy with this setting for a given location:

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Forwarded-Host $the_host;
proxy_set_header X-Forwarded-Proto $the_scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

gzip off;

proxy_buffering off;
proxy_cache off;
proxy_pass http://my_upstream;
proxy_read_timeout 90;
proxy_redirect http://my_upstream https://www.my_fqdn.com;

A request comes in for this location. Nginx connects the upstream, which is a tomcat server. The tomcat server connects a new ZipOutputStream with the response and starts streaming files into it. Total download size can be huge. (In this concrete case it is about 2GB.)

This is what I experience:

* firefox starts downloading the zip file
* after about 500MB of download, tomcat throws this error:

```

tomcat01.0.p3kiinawp7n9@dev | org.apache.catalina.connector.ClientAbortException: java.net.SocketTimeoutException
tomcat01.0.p3kiinawp7n9@dev | at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:351)
tomcat01.0.p3kiinawp7n9@dev | at org.apache.catalina.connector.OutputBuffer.flushByteBuffer(OutputBuffer.java:776)
tomcat01.0.p3kiinawp7n9@dev | at org.apache.catalina.connector.OutputBuffer.append(OutputBuffer.java:681)
tomcat01.0.p3kiinawp7n9@dev | at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:386)
tomcat01.0.p3kiinawp7n9@dev | at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:364)
tomcat01.0.p3kiinawp7n9@dev | at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:96)
tomcat01.0.p3kiinawp7n9@dev | at java.base/java.util.zip.DeflaterOutputStream.deflate(DeflaterOutputStream.java:253)
tomcat01.0.p3kiinawp7n9@dev | at java.base/java.util.zip.ZipOutputStream.closeEntry(ZipOutputStream.java:256)

```

* firefox continues to download the zip file for another minute or so, like nothing happened.
* after that, firefox throws "download failed" error and the download is aborted
* at the exact same moment, the request appears in nginx access log with HTTP 200 status code (not suprisingly, because the HTTP 200 header was set before the data streaming had started)

I think I have already disabled caching for this particular API endpoint in nginx. I'm not sure what is happening, but this is what I suspect:

* tomcat streams the data very fast
* firefox cannot keep up with this, the TCP buffer fills up
* tomcat repeatedly tries to write to the socket but it can't and SocketTimeout is raised

But I may be wrong. It is very suspicious that firefox downloads several hundred MB of data after tomcat has thrown the execption.

Questions:

* Is my nginx config correct? Should I change something in the nginx config?
* Am I missing anything else that will prevent me streaming gigabytes of data into a request like this, **possibly for hours**?
* How can I control the socket timeout on the tomcat (java) side? I could not find any method on HttpServletResponse that would change the timeout. This part of the question is not strictly related to nginx, and possibly there is nothing wrong with my tomcat setup.
Viewing all 2931 articles
Browse latest View live