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

Cannot pass well to external site + cannot manipulate responses

$
0
0
Hello, i'm new at nginx and i'm trying to set up the proxy to do the following tasks:
1. all requests will be passed into an external site
2. change specific strings (later i want to do more complex logic).

i'm trying to forward all traffic to an external domain for example:

my configuration is as follow:

server {
listen 80;
location / {
proxy_pass https://external.com;

proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_request_headers on;

sub_filter_once off;
sub_filter_types *;
sub_filter "Welcome" "Test";
}

I'm able to be redirected to the external domain and surf, but there are few problems:
1. some sites for example handle csrf attacks, any anything else - i'm aware that i'm going through a proxy but i want to retain all the original requests and i'm not sure what gets lost (for example trello blocks me for csrf detection).
2. the rewrite just doesn't work, nothing in the response body is changed.

Assistance will be appreciated.

Nginx + PHP 7

$
0
0
Hi folks,

I'm very sorry if this one is going to cause some folk to shake their heads in dismay.. but I genuinely CANNOT get Nginx to process PHP. I have tried numerous different configurations and workarounds found in all corners of the Google webs.

Ubuntu 14.04
Nginx 1.4.6
PHP 7.0

I've tried numerous different setups for the Nginx 'default' file, this is the current:

________________

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

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

server_name server_domain_or_IP;

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

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass /run/php/php7.0-fpm.sock;
}

location ~ /\.ht {
deny all;
}
}
______________________

I've also ensured cgi.fix_pathinfo=0 in /etc/php/7.0/fpm/php.ini.

I've restarted Nginx, restarted php-fpm and restarted the server numerous times.

I CANNOT get Nginx to do anything other than offer a PHP file as a download via Chrome or simply display the PHP contents via IE / Edge.

I'm at my wits end, I very rarely seek help in situations like this. Normally I'd stick with it until I worked it out. I've been at it 3 hours now though.. help!

Re: Wordpress in subdirectory

$
0
0
Sorry for the late reply. Thanks so much for your response I will try applying this config tonight hopefully and let you know how it plays out.

Use NGINX to proxy a website that uses windows authentication

$
0
0
Hi,

I'm well aware of the security implications of the thing that I'm trying to do but I would like to accomplish this just for testing purposes. Is it possible (for testing environment only of course) to set NGINX as a reverse proxy to a website that uses Integrated Windows Authentication but set NGINX not to require authentication at all (or at least use basic authentication only) and instead use credentials that will be specified in the NGINX config files?

Tnx.

NGINX vs SQUID

$
0
0
Hi,

Is it possible to set NGINX as a FORWARD proxy so that requests arriving at a specific port will go through (for example) eth0, and requests arriving at another port will go through eth1 and so on?

Tnx.

caching issue on fast requests

$
0
0
Hello
Sorry if there is simmilat topic already, but I didn't find it

I'm using Vesta 0.9.8 (i686) Release: 17

httpd-2.2.15-115.el6.1.i386
nginx-1.12.1-1.el6.ngx.i386
vesta-nginx-0.9.8-17.i686

I have a simple php script that shows user IP. But I'm noticed a problem. When I'm making many requests to this script at the same time from different IP's via proxy - it returns same result page for most requests.

Example:
IP 111.111.111.111 - Result: 111.111.111.111
IP 111.111.111.112 - Result: 111.111.111.111
IP 111.111.111.113 - Result: 111.111.111.111
IP 111.111.111.114 - Result: 111.111.111.111
IP 111.111.111.115 - Result: 111.111.111.115
IP 111.111.111.116 - Result: 111.111.111.115

Looks like some kind of caching.
So I checked nginx setting and tried to add bypass instructions into php.ini
proxy_cache_bypass $http_pragma $cookie_nocache $arg_nocache$arg_comment;

Also from client side I've added headers
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache

It didn't helped.

Currently server response looks like:
----------------------------------------------------------
HTTP/1.0 200 OK
Server: nginx
Date: Fri, 27 Oct 2017 20:03:37 GMT
Content-Type: text/html; charset=UTF-8
X-Powered-By: PHP/5.6.31
Connection: keep-alive
Content-Length: 14

111.111.111.115
----------------------------------------------------------

What I'm doing wrong?

yet another redirect... from one path to another /path1/ -> /path2

$
0
0
Question 1:
Now i want to make old links https://domain.tld/performers/ into https://domain.tld/models/ how do I do that? have tried quite a few things I've been able to locate by searches, but not one do it right for me

Here is my rewrite (optimisation suggestions ok :) )

location /models {
rewrite ^/(performers|models)/$ /index.php?controller=models;
rewrite ^/(performers|models)/(alphabetical|rating)/$ /index.php?controller=models&sortby=$2;
rewrite ^/(performers|models)/page([0-9]+).html$ /index.php?controller=models&page=$2;
rewrite ^/(performers|models)/(alphabetical|rating)/page([0-9]+).html$ /index.php?controller=models&sortby=$2&page=$3;
rewrite ^/(performers|models)/(.*)/page([0-9]+).html$ /index.php?controller=models&letter=$2&page=$3;
rewrite ^/(performers|models)/(.*)/(alphabetical|rating)/$ /index.php?controller=models&letter=$2&sortby=$3&page=1;
rewrite ^/(performers|models)/(.*)/(alphabetical|rating)/page([0-9]+).html$ /index.php?controller=models&letter=$2&sortby=$3&page=$4;
rewrite ^/(performers|models)/(.*)-([0-9]+).html$ /index.php?controller=model_bio&id=$3 last;
rewrite ^/(performers|models)/(.*)/$ /index.php?controller=models&letter=$2&page=1;
}



Question 2

if I should redirect from https://domain.tld/media/ to https://media.domain.tld/ and by that skip the /media in the url, I can't use the return 301 https://$server_name$request_uri; as that would add the /media to the url and then fails..

Re: Streaming To Wordpress

$
0
0
You can do something like this; You'll have to find the explanations on nginx.org, but basacly it will forbid other that your own server to show the videos and limit the speed to 1mbit after 10 min

location ~ \.mp4$ {
#internal;
#alias /var/www/domain.tld/media/videos;
valid_referers none blocked server_names
domain.tld
*.domain.tld
if ($invalid_referer) {
rewrite ^ https://www.domain.tld/?;
}
secure_link $arg_md5,$arg_expires;
secure_link_md5 "$secure_link_expires$remote_addr some_secrets";
if ($secure_link = "") {
rewrite ^ https://www.domain.tld/?;
}

if ($secure_link = "0") {
return 410;
}

mp4;
limit_rate_after 10m;
limit_rate 1M;
mp4_buffer_size 5m;
mp4_max_buffer_size 15m;
sendfile on;
aio on;
expires 18000;
add_header X-Frame-Options SAMEORIGIN;
}

Re: reloading nginx with tons of virtual hosts

$
0
0
This is somewhat common, it's not every time a systemctl reload nginx can do the trick, but you'll need to do a full restart (systemctl restart nginx) especially if you are using ssl

Re: how to start serving

$
0
0
Try to read the /etc/nginx/conf.d/default you might get an idear there :)

else please read the https://nginx.org/en/docs/ there are plenty of starter guides

Re: How to setup a website with nginx, centos and a domain registed on cloudflare?

$
0
0
Here is many questions not answered to make this easy, but i'll understand it like you would run your .php on the slow apache and then use the nginx as reversed frontend for apache..... but since you don't know about how to do this, you properly don't have a lot of visitors, so I'll suggest you skip the apache and go directly into nginx with php-fpm and reverse into that

guide for that part is here https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html

Next you'll have to simply fullow the https://nginx.org/en/docs/ to set it up

but..

make a /etc/nginx/conf.d/mysite.conf

make it listen to your ip

open port :80 on the vps and you are close

the most very basic ex. of a conf file looks somewhat like this

server (
listen 155.94.xxx.15x:80;
listen 155.94.xxx.15x:443;
server_name yourdomain.tld www.yourdomain.tld;
root /full/path/to/your/html/files;
index index.php index.html;
}

thi will now serve static *.html files from /full/path/to/your/html/files/ starting with the index.html

Re: play interruptions during reloads

$
0
0
Post your mp4 conf part for debug

Re: Address already in use

$
0
0
First: what is listening to port 80

lsof -i :80

properly apache :P, but kill all services listening to port 80 and the try to restart your nginx...
Alternatively add ip directives to the listener like
listen 123.123.123.123:80
to the configs

Re: reloading nginx with tons of virtual hosts

$
0
0
Hi JoakimR,
I solved the problem replacing the entry in crontab.
The command "service nginx reload" executed as root by crond caused the problem, instead, service nginx reload executed as root from terminal worked flawlessly.

So I replaced "service nginx reload" with "/etc/init.d/nginx reload" in crond and everything worked perfectly.

Thank you for your help.

Problem with multiple websites

$
0
0
I currently own two websites (passthemayo.space and botlist.space). I want to run both of them on Nginx through SSL. I currently have SSL certificates for both of them, and ready to use, but I have a problem. The two websites are using port 443, and one is unable to start because the other is already using the port. Here is all of my configs:

default (passthemayo.space): https://hastebin.com/oqexuvaqew.nginx
haste (haste.passthemayo.space): https://hastebin.com/oromonisow.nginx
list (botlist.space): https://hastebin.com/apecanobok.nginx

When I try to use that, I get the following error: https://hastebin.com/avikalexib.log

Hope you guys can help me fix this. Thanks!

Re: Problem with multiple websites

$
0
0
One nginx can listen on 443 and handle multiple websites via multiple server {} blocks, you can't have two nginx instances using the same port, merge all sites in one instance.

Re: Problem with multiple websites

$
0
0
Thanks, but I have actually already fixed it. Someone in a discord channel had helped me.

How to proxy_pass a redirect chain (Multiple domains)

$
0
0
Hey guys,

How can I set nginx to reverse proxy a redirect chain?

I mean, my problem looks like that:

First URL: http://first-domain.com/?parameters=987654321

(The first domain will use JS redirect to: http://second-domain.com/?parameters=987654321

The second domain will use 301 redirect to: http://third-domain.com/?parameters=987654321

My question is:

How can I use proxy_pass (or_something_else) to send the user to http://third-domain.com/?parameters=987654321 mantaining the ip of my reverse proxy?

Uniquely identify the client

$
0
0
I'm developing a web app using Node.js and I came across the following npm package that does more or less what I am looking for. That is to somehow uniquely identify the client that connects to my server.

https://github.com/yusukeshibata/express-fingerprint

This work great during local development and on the staging environment though in production I always use nginx and I'm wondering if is even possible to achieve the same functionality as those offered by the express-fingerprint package.

The package for instance uses the following sources to create a fingerprint of the connected client:

User Agent
HTTP_ACCEPT Headers
GEO-ip

Then create a fingerprint of the above and hash the result.

The only out of the box solution for nginx I found is the geoip functionality:
http://nginx.org/en/docs/http/ngx_http_geoip_module.html

Is there anything else that could cover headers and user agent ($http_user_agent??) like express-fingerprint? Let alone hashing them on nginx to lessen the load of my server.

Thank you.

Redirects not working

$
0
0
I am very new to using nginix.
I have it running in ubuntu 16.04 VM in AWS.
This ubuntu server is sitting behind AWS ALB.
I am trying to redirect some pages from 1 site to an external site.

ALB does path based routing.
If there is any request coming with local /es-mx I want to route to another server.
Here my complete setup

If I send a request like this

http://rzr-test.disco.com/es-mx

It does get routed to http://rzr-qa.disco.com/es-mx

Howerver, If I send a request like
http://rzr-test.disco.com/es-mx/page1 I expect it to be routed to
http://rzr-qa.disco.com/es-mx/page1

But it does not happen. It does not get redirected.
I have tested my paths in online nginx tester and they see to work but something is wrong my setup.


server {
listen 80;
server_name rzr-test.disco.com;
root /var/www/html;

location ~* ^/es-mx/ {
return 301 $scheme://rzr-qa.disco.com$request_uri;
}

location ~* ^/es-mx {
return 301 $scheme://rzr-qa.disco.com$request_uri;
}

location / {
}
}

server {
listen 80;
server_name rzr-qa.disco.com;

#rewrite ^/es-mx/(.*)$ /en-us/$1 last;
location / {
#rewrite ^/es-mx/(.*)$ /en-us/$1 last;
proxy_pass http://rzr-qa.disco.com;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header Proxy "";
proxy_cache_bypass $http_upgrade;
}
}
Viewing all 4759 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>