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

Piped Logs in nginx

$
0
0
Hi everyone,

in Apache, there is a "Piped Logs" feature [1], which makes it possible to write error and access log files through a pipe to another process, rather than directly to a file; it's configured like this:

CustomLog "|/path/to/script param1" common

Is something like that possible with nginx, too?
If so, how? I could not find a mature technique to do this.

[1] http://httpd.apache.org/docs/current/logs.html#piped

Nginx reverse proxy and load balancer at the same time with raspberry

$
0
0
Hi,
I'm building a cluster based on raspberry. This cluster contains 4 nodes (raspberry). Three of them each host an Apache server, whose purpose is to deploy a Web application designed in PHP. The fourth, I would configure it as a reverse proxy and load balancer at the same time with NGINX. The three Apache nodes have a static IP address of the form 192.168.0.x, so the problem is that the raspberry has only one rj45 interface. How to configure the fourth node (reverse proxy and load balancer with nginx) with 2 ip addresses, one from my router and the other in the same network as the 3 nodes Apache (192.168.0.x)? Will it be necessary to add a rj45 interface? Or is there another alternative? Thank you in advance for your answers.

Help : Nginx redirecting to wrong webpage

$
0
0
HI,

can you help me with this problem where nginx is showing an old webpage.
Even though there's no index.html in /var/www/kaufranitz it loads that old page ?

Here's the sites-enabled/default conf :

server {
listen 80;
listen 443 ssl spdy;

root /var/www/kaufranitz;
index index.php;

server_name kaufranitz.net www.kaufranitz.net;

ssl_certificate /etc/letsencrypt/live/kaufranitz.net/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/kaufranitz.net/privkey.pem;

location / {
try_files $uri $uri/ =404;
}

location ~\.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
try_files $uri =404;
include fastcgi_params;
}
}

Hope I'm clear enough and thanks for your help,

Camaalot

Nginx times out after Unoconv fails to convert XLSX to PDF

$
0
0
We use Unoconv to convert XLSX files to PDF and the same is done by calling Unoconv as:

putenv('PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/node/bin');
$tmp_path = '/home/around/libreoffice_tmp';
$tmp_output_file = '/home/around/libreoffice_tmp/output.txt';
$cmd = 'echo ' . $tmp_path . ' & echo $PATH & UNO_PATH=/usr/lib/libreoffice & /usr/bin/unoconv --format pdf --output ' . $output_file_pdf . ' ' . $output_file_excel . ' 2> ' . $tmp_output_file;
$output = '';
$result_var = '';
exec($cmd, $output, $result_var);

Request flows from our web application using Codeigniter 2.x / PHP 5.5 and Nginx 1.4.6 running on Ubuntu 14.04. LibreOffice 4.2.8.2 420m0(Build:2) and Unoconv 0.6 is installed.

Generally we don't face any issue and XLSX files get converted to PDF. But sometimes, this piece of code fails (we don't see log below this code in our log files) and Nginx starts returning time out (504 error) to our users.

If I do htop at that time, I find the CPU load very low and ~700MB+ RAM available out of 7GB. Mysql also responds to the requests placed directly to it through terminal. But everything fails when requests come through Nginx.

Ultimately, I need to restart FPM to make things work again:

sudo service php5-fpm restart

I checked nginx error logs in /var/log/nginx/ but could not find anything there. I checked error log in /var/www/mydomainname.com/logs/error.log and found:

2017/04/12 14:36:10 [error] 1871#0: *45903 open() "/var/www/mydomainname.com/public_html/employee/images/loading.gif" failed (2: No such file or directory), client: 117.217.202.199, server: www.mydomainname.com, request: "GET /employee/images/loading.gif HTTP/1.1", host: "mydomainname.com", referrer: "https://mydomainname.com/employee/login"
2017/04/12 14:36:12 [error] 1871#0: *45903 open() "/var/www/mydomainname.com/public_html/employee/images/loading.gif" failed (2: No such file or directory), client: 117.217.202.199, server: www.mydomainname.com, request: "GET /employee/images/loading.gif HTTP/1.1", host: "mydomainname.com", referrer: "https://mydomainname.com/employee/login"
2017/04/12 14:36:16 [error] 1871#0: *45903 open() "/var/www/mydomainname.com/public_html/employee/images/loading.gif" failed (2: No such file or directory), client: 117.217.202.199, server: www.mydomainname.com, request: "GET /employee/images/loading.gif HTTP/1.1", host: "mydomainname.com", referrer: "https://mydomainname.com/employee/login"
2017/04/12 14:40:02 [error] 1869#0: *46395 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center/pending_booking HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com", referrer: "https://mydomainname.com/service_center/search"
2017/04/12 14:41:41 [error] 1870#0: *46448 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center/pending_booking HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com", referrer: "https://mydomainname.com/service_center/search"
2017/04/12 14:41:45 [error] 1870#0: *46452 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center/pending_booking HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com", referrer: "https://mydomainname.com/service_center/search"
2017/04/12 14:48:42 [error] 1869#0: *47276 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center/pending_booking HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com", referrer: "https://mydomainname.com/service_center/search"
2017/04/12 14:49:34 [error] 1869#0: *47332 open() "/var/www/mydomainname.com/public_html/partner/images/loading.gif" failed (2: No such file or directory), client: 117.217.202.199, server: www.mydomainname.com, request: "GET /partner/images/loading.gif HTTP/1.1", host: "mydomainname.com", referrer: "https://mydomainname.com/partner/login"
2017/04/12 14:50:08 [error] 1869#0: *47366 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center/pending_booking HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com", referrer: "https://mydomainname.com/service_center/search"
2017/04/12 14:50:27 [error] 1869#0: *47381 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center/pending_booking HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com", referrer: "https://mydomainname.com/service_center/search"
2017/04/12 14:51:22 [error] 1870#0: *47418 open() "/var/www/mydomainname.com/public_html/employee/images/loading.gif" failed (2: No such file or directory), client: 122.177.19.147, server: www.mydomainname.com, request: "GET /employee/images/loading.gif HTTP/1.1", host: "mydomainname.com", referrer: "https://mydomainname.com/employee/login"
2017/04/12 14:51:24 [error] 1871#0: *47468 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center/pending_booking HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com", referrer: "https://mydomainname.com/service_center/search"
2017/04/12 14:51:44 [error] 1871#0: *47539 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center/pending_booking HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com", referrer: "https://mydomainname.com/service_center/search"
2017/04/12 14:52:11 [error] 1869#0: *47633 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center/pending_booking HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com", referrer: "https://mydomainname.com/service_center/search"
2017/04/12 14:52:23 [error] 1869#0: *47838 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com"
2017/04/12 14:52:27 [error] 1869#0: *47838 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com"
2017/04/12 14:52:39 [error] 1871#0: *47996 open() "/var/www/mydomainname.com/public_html/employee/images/loading.gif" failed (2: No such file or directory), client: 122.177.19.147, server: www.mydomainname.com, request: "GET /employee/images/loading.gif HTTP/1.1", host: "mydomainname.com", referrer: "https://mydomainname.com/employee/login"
2017/04/12 14:52:53 [error] 1869#0: *48042 upstream sent too big header while reading response header from upstream, client: 122.177.49.3, server: www.mydomainname.com, request: "GET /service_center HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "mydomainname.com"

I had also enabled nginx slow error logs and mysql slow logs but could not find anything there as well.

libreoffice_tmp/output.txt had these errors which I could not fix:

mkstemp("/var/www/.execooo7qvnSr") failed: Permission denied

As of now, we have stopped using unoconv and the 504 error has not come so far. But we need to convert our files to PDF so we need to enable it again.

Is there something which we have done wrong? Can a system call failure results in Nginx hang? Is there some other log file I should look at? Please help as even after spending so much time in debugging this issue, we are still clueless.

Nginx config file is:

server {
listen 80;
server_name mydomainname.com;
rewrite ^ https://$server_name$request_uri? permanent;
}

server {
listen 443;
# listen 80;
server_name www.mydomainname.com;
access_log /var/www/mydomainname.com/logs/access.log;
error_log /var/www/mydomainname.com/logs/error.log;
root /var/www/mydomainname.com/public_html;
index index.html index.htm index.php;
ssl on;
ssl_certificate /etc/nginx/mydomainname_ssl_3jul2016/mydomainname_final.crt;
ssl_certificate_key /etc/nginx/mydomainname_ssl_3jul2016/server.key;

##To _disable SSLv3, your ssl_protocols directive should be _set like this##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

# proxy_cache one; this needs to be commented

location ~* .(jpg|jpeg|png|gif|ico|css|js|woff|ttf)$
{
expires 1h;
}
location / { try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
if ($uri !~ "^/images/") {
# fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass 127.0.0.1:9000;

#fastcgi_read_timeout 300;

}

nginx proxy_pass to puppetmaster

$
0
0
Hi,

I want to use nginx to proxy_pass puppet client requests to my puppet master.

My config:

upstream puppetmaster {
server 192.168.3.10:8140; #
}
server {
listen 192.168.3.200:8140;
server_name puppetmaster.mydom.de;
ssl on;
ssl_certificate /etc/nginx/ssl/puppet.crt;
ssl_certificate_key /etc/nginx/ssl/puppet.key;
ssl_client_certificate /etc/nginx/ssl/puppet.ca-crt;
ssl_crl /etc/nginx/ssl/puppet.ca_crl;
ssl_verify_client optional;

access_log /var/log/nginx/puppetmaster.ssl.log;
error_log /var/log/nginx/puppetmaster.ssl.err.log;

root /srv/www/htdocs;
index index.html index.htm;


location / {

proxy_pass https://puppetmaster;
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-Client-Verify $ssl_client_verify;
proxy_set_header X-SSL-Subject $ssl_client_s_dn;
proxy_set_header X-SSL-Issuer $ssl_client_i_dn;
proxy_redirect off;
}
}


My clients get this error message:

Warning: Unable to fetch my node definition, but the agent run will continue:
Warning: Error 403 on SERVER: {"message":"Not Authorized: Forbidden request: /puppet/v3/node/myhostname [find]","issue_kind":"RUNTIME_ERROR"}


Can anybody help me?

thx

nginx + rewrite + try_files

$
0
0
Hi,
I use Nginx for a file distribution on a server with a lot of files. Files is requested by URI like http://hostname/files/somefiles/GUID/UID/filename.zip.
Because there is a really tonn of files on server, I use five storage devices, which is mounted on root fs and store files like this:
/mnt/st0/sf/guid/uid/file1.zip
/mnt/st1/sf/guid/uid/file2.zip
/mnt/st2/sf/guid/uid/file3.zip
/mnt/st3/sf/abc/guid/def/uid/file4.zip
/mnt/st4/sf/abc/guid/def/uid/file5.zip
where ABC is a first 3 symbols of GUID and DEF is a first 3 symbols of UID.
At this time I use rewrite + try_files:
---
location /files/somefiles/ {
root /;
rewrite "^/files/somefiles/(.*)$" "/sf/$1" break;
try_files /mnt/st0$uri /mnt/st1$uri /mnt/st2$uri @uri3s;
}
location @uri3s {
root /;
rewrite "^/sf/([A-F0-9]{3})([A-F0-9-]{33}/)([a-f0-9]{3})(.*\.zip)$" "/$1/$1$2/$3/$3$4" break; #GUID lenth is 33 uppercase symbols, UID is always in lowercase.
try_files /mnt/st3/sf$uri /mnt/st4/sf$uri =404;
}
---
All works fine in test envirorment, but on production server with 6k rpm I have LA about 6.
How can I optimize this?

ip_hash, how to

$
0
0
Hello

I have webserver application running on ports 82, 83 and 84, on same server. Here is my nginx conf:

worker_processes 1;
events {
worker_connections 1024;
}
#Server groups#
http {
upstream backend {
hash $remote;
ip_hash;
server localhost:82;
server localhost:83;
server localhost:84;
}
server {
listen 81;
location / {
proxy_pass http://backend;
}
}
}
What I need is that new clients (with different IP addresses) are connected like this:
Client1 to 82
Client2 to 83
Client3 to 84
Client4 to 82
Client5 to 83
etc.
With other words, new clients (with new IP address) need to be connected to different port.
Now, I have 3 clients running on different IP addresses and Client1 is connected to 82 but Client2 and Client3 are connected to 83 (to same IP).
How I need to write conf file that new clients are loaded balanced?
Thank you.

open_file_cache storage location and verification

$
0
0
I am configuring a server with open_file_cache settings. I would like to verify that the open_file_cache is active and working. Is there a way to do this? Also, how would I go about finding the cache directory where the cached files are stored on the server (Debian)?

Nginx and Nodejs app on RPi2 - Routing issues

$
0
0
I originally configured the nodejs app on the rpi2 behind a linksys router and the app responded fine from an outside server.

Then I installed nginx and added https with a certificate from letsencrypt and it served the https site just fine to my Mac on the same network.

Now that I'm trying to combine the two, but it's not working, I get a 404 not found. My app is at:

/www/subdomain.domain.com/aism/app.js

The nginx config for that /etc/nginx/sites-available/subdomain.domain.com is as follows:

[code]
server {
listen 80;
listen [::]:80;
server_name subdomain.domain.com;
return 301 https://$server_name$request_uri;
}

server {
listen 443 ssl;
listen [::]:443 ssl;
server_name subdomain.domain.com;

ssl_certificate /etc/letsencrypt/live/subdomain.domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/subdomain.domain.com/privkey.pem;

root /www/subdomain.domain.com;
index index.php index.html index.htm;

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /www/subdomain.domain.com;
}

# Error & Access logs
error_log /www/subdomain.domain.com/logs/error.log error;
access_log /www/subdomain.domain.com/logs/access.log;

location / {
index index.html index.php;
proxy_pass http://LocalLanIp:442;
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 ~ /.well-known {
allow all;
}

location ~ [^/].php(/|$) {
fastcgi_split_path_info ^(.+?.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
[/code]

Re: Nginx and Nodejs app on RPi2 - Routing issues

$
0
0
I just checked the error log and it looks like this:

[code]
2017/04/23 19:30:48 [error] 20219#0: *1 upstream prematurely closed connection while reading response header from upstream, c$
2017/04/23 19:30:48 [error] 20219#0: *1 open() "/www/subdomain.domain.com/aism/50x.html" failed (2: No such file or directory$
[/code]

Re: Nginx and Nodejs app on RPi2 - Routing issues

$
0
0
I removed the 50x.html line in the config. Now I get this bad gateway error from hurl.it & the error log on the pi looks like this:

2017/04/23 19:48:27 [error] 20302#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 23.20.198.108, server: subdomain.domain.com, request: "POST /API/switches/sw1?password=123456 HTTP/1.1", upstream: "http://192.168.1.53:442/API/switches/sw1?password=123456", host: "subdomain.domain.com"
2017/04/23 19:48:27 [error] 20302#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 23.20.198.108, server: subdomain.domain.com, request: "POST /API/switches/sw1?password=123456 HTTP/1.1", upstream: "http://192.168.1.53:442/50x.html", host: "subdomain.domain.com"

Thats the correct localLanIP for the rpi and the 442 port is whats configured in the .env file for the app.js to listen for.

Do I need to install php to run nginx?

$
0
0
Im trying to run a nodejs app behind nginx as reverse proxy on https. Do I need to have php installed on my rpi?

Re: ip_hash, how to

nginx proxy cache with same file name but any context

$
0
0
Hello.

I want to caching some html files, with the same file name, but with any (wildcard?) context. It's a bit difficult to me to explain, but:

domain.com/getContentById /123456/abcdef/content.html
domain.com/getContentById /123456/fedcba/content.html
domain.com/getContentById /123456/blahblah/content.html

All this are the same "content.html" and need to be caching as the same file


domain.com/getContentById /654321/abcdef/content.html
domain.com/getContentById /654321/fedcba/content.html

Another content.html, but need caching too (only to the last 2 URLs).

My nginx related config doesn't works:

location ~* /getContentById {

proxy_pass http://servers;
proxy_cache mycache;

proxy_connect_timeout 5s;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_cache_valid 200 1d;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;

}

Re: Nginx and Nodejs app on RPi2 - Routing issues


split traffic based on uri

$
0
0
Hello,

Working on a new version of a web app, I need to redirect some uri to the new version (including /) while keeping not reworked pages on the old version. Old and new versions are hosted on differents servers.

Currently my solution is half-working because pages (php rendered) are correctly loaded from old or new versions, but all the statics assets (img, css, js) are loaded from old version. I guess this is because of the last location block :

location ~* /uri_v2/ {
try_files $uri $uri/ @v2;
access_log off;
}

location = / {
try_files $uri $uri/ @v2;
access_log off;
}

location / {
try_files $uri $uri/ @v1;
access_log off;
}

location @v1 {
proxy_pass http://v1.webapp.com;
proxy_set_header Host webapp.com;
add_header X-version v1;
add_header X-node $hostname;
}

location @v2 {
proxy_pass http://v2.webapp.com;
proxy_set_header Host webapp.com;
add_header X-version v2;
add_header X-node $hostname;
}

I can't find any logical solution to make this works. How can I tell nginx to load page's related content from the same backend that served the page ?

Thank you.

Bad Gateway on NGinx route to nodejs

$
0
0
This is what my setup looks like:

INTERNET (subdomain.domain.com A Record to public IP 186....187)
Hurl.it -----POST-----> Public IP: https://186....187/API/switches?sw1?password=123456 -----> Linksys Router IP:186...187:443 Port Forward to 192...53

ONLAN (nginx setup https with ssl from letsencrypt)
192....53 RPi2 nginx config bypass 192...53:442 . ------> nodejs app.js listening on port 442

This is my nginx config file:

[code]
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name subdomain.domain.com;

ssl_certificate /etc/letsencrypt/live/subdomain.domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/subdomain.domain.com/privkey.pem;

root /www/subdomain.domain.com/aism;
index index.php index.html index.htm;

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;

# Error & Access logs
error_log /www/subdomain.domain.com/logs/error.log error;
access_log /www/subdomain.domain.com/logs/access.log;

location / {
index index.html index.php;
proxy_pass http://192.168.1.53:442;
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 ~ /.well-known {
allow all;
}
location /public {
root /www/subdomain.domain.com/aism;
}
location ~ ^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/) {
}
}[/code]

I have tested the nodejs app while on port 80 from hurl.it with the port forward config for port 80 instead and it works perfectly.

Here is the current error log:

[quote]
OST /API/switches/sw1?password=123456 HTTP/1.1", upstream: "http://192.168.1.53:442/50x.html", host: "subdomain.domain.com"
2017/04/23 20:08:38 [error] 20424#0: *4 upstream prematurely closed connection while reading response header from upstream, client: 192.168.1.56, server: subdomain.domain.com, request: "GET /aism/ HTTP/1.1", upstream: "http://192.168.1.53:442/aism/", host: "subdomain.domain.com"
2017/04/23 20:08:38 [error] 20424#0: *4 upstream prematurely closed connection while reading response header from upstream, client: 192.168.1.56, server: subdomain.domain.com, request: "GET /aism/ HTTP/1.1", upstream: "http://192.168.1.53:442/50x.html", host: "subdomain.domain.com"
2017/04/23 20:09:25 [error] 20467#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 23.20.198.108, server: subdomain.domain.com, request: "POST /API/switches/sw1?password=123456 HTTP/1.1", upstream: "http://192.168.1.53:442/API/switches/sw1?password=123456", host: "subdomain.domain.com"
[/code]

Please help!

Major Manipulate Doubts (couldn't find anywhere)

$
0
0
Hello, i have the following specifc doubts:

1st: it`s possible to concat variables? i mean i want to do an if statement like this:
if ($host$request_uri ~ ^https?:\/{2}([^w]{3})(.*)\/$) {
set $redirect_option 3
}

But so far i wasn`t able to get the full url (domain + uri), only one or other and this is crippling me :/

2nd: Trying to find out a solution (assuming i can`t have the full url to match with regex), i`ve tried something like this:


XYZ are conditions ommited here

set $redirect_condition 0;
if ($force_ssl = XYZ) {
set $redirect_condition 1;
}

if ($request_uri ~ ^/healthcheck(.*)$) {
set $redirect_condition 0;
}

if ($request_uri ~ ^/(.*)/$) {
set $redirect_condition 2;
}

if ($host ~ ^https?:\/\/[^w](.*)) {
set $redirect_condition "${redirect_condition}3";
}

try_files $uri/index.html $uri @unicorn;
location @unicorn {
if ($http_x_forwarded_proto = "https") {
add_header Strict-Transport-Security "max-age=60; includeSubDomains";
}

if ($redirect_condition = 23) {
rewrite ^/(.*)/$ https://www.anydomain.com/$1 permanent;
}


if ($redirect_condition = 1) {
rewrite ^ https://$host$request_uri? permanent;
}

if ($redirect_condition = 2) {
rewrite ^/(.*)/$ https://$host/$1 permanent;
}



Any suggestion to make it works? TY

Reverse proxy with multiple interfaces

$
0
0
I use NGINX to reverse proxy incoming requests from a network interface to a WIldfly application server listening on port 8080. The config is simple:

server {
listen 80;
server_name application.mynet.com;

location /myapplication {
proxy_pass http://127.0.0.1:8080/myapplication/;
}
}

That works as expected. But what if I add a second network interface to the box such that requests from the LAN arrive on one interface, requests from the internet on the other? Let's say that the two interfaces have address 192.168.10.10 and 192.168.20.20 - Is this valid? The incoming URL is the same in both cases, but they are handled differently depending on the interface the request arrived on.

// If the request came from the LAN interface, route it to myapplication
location /myapplication {
proxy_bind 192.168.10.10
proxy_pass http://127.0.0.1:8080/myapplication/;
}

// If the request came from the Internat interface, route it to someotherapplication
location /myapplication {
proxy_bind 192.168.20.20
proxy_pass http://127.0.0.1:8080/someotherapplication/;
}

Thanks.

Forwarding port 80 requests using reverse proxy

$
0
0
Hello all,

I am not very technologically savvy in the networking realm and I apologize if I fall behind on certain terminology ahead of time.
I have a dynamic dns domain through noip.com, which I will reference as domain.example. I also have a public IP address which I will reference as 68.***.***.***.

The dynamic dns domain (domain.example) is assigned to my public IP address (68.***.***.***). I have an AirPort Extreme that I can open ports on and I have it configured as such: http://imgur.com/a/Ig0Ay.

Basically what I am trying to do is when someone accesses domain.example, I want nginx to forward them to domain.example:3001. Currently I am able to open port 80 on my router and I can navigate to domain.example with my LAN, but as soon as I travel outside of my house, it doesn't work... I know that my ISP blocks 80 for residential accounts and this is why I am attempting to setup this domain forwarding. Please any help would be greatly appreciated!




This is my current nginx configuration:



#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 {
include mime.types;
default_type application/octet-stream;

#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;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 80;

server_name 68.***.***.*** domain.example localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root html;
index index.php index.html index.htm;
proxy_pass http://127.0.0.1:3001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ /.php$ {
# proxy_pass http://127.0.0.1;
#}

#pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME c:/nginx/html$fastcgi_script_name;
include fastcgi_params;
}

#deny access to .htaccess files, if Apache's document root
#concurs with nginx's one

location ~ /\.ht {
deny all;
}
Viewing all 4759 articles
Browse latest View live