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

Reverse Proxy Forward

$
0
0
Hi all,

I have Nginx running and being used primarily as a reverse proxy. So far all is running well for web services, but I am having a problem proxying requests from/to an internal service running for Sophos message relaying. This service uses ports 8192-8194. I allowed these through the firewall on my box (Centos) and then setup the usual server blocks in my reverseproxy config which sends them on to the internal server. An example is below.

server {
listen 8192;
server_name My_Server;

access_log /etc/nginx/logs/sophos_relay_ports/access.log;
error_log /etc/nginx/logs/sophos_relay_ports/error.log debug;

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://My_Internal_Server:8192;
proxy_read_timeout 150;
proxy_buffering off;
proxy_redirect off;

}
}

I can;'t seem to figure out why the traffic is not reaching the destination. Does anyone have a suggestion?

Thanks.

Regards,
R

hiding php parameters

$
0
0
Hello everyone.

I have a website with this kind of adresses:

https://www.mydomain.com/user/userprofile/[userprofile1]?r=[login]&w=[encryptedpassword]

ie:

https://www.mydomain.com/user/userprofile/toto?r=reqqfdvca&w=skvlsqmg
https://www.mydomain.com/user/userprofile/titi?r=re45a&w=slkvldfgmg
https://www.mydomain.com/user/userprofile/tutu?r=reqq0krgca&w=s46893ls
etc...

the parameters are important because there are credentials to access the website but I would like my adresses to look like:

https://www.mydomain.com/user/userprofile/toto
https://www.mydomain.com/user/userprofile/titi
https://www.mydomain.com/user/userprofile/tutu
etc...

I'm new with nginx, and my english is not perfect so please excuse my mistakes, but does anyone have an idea on how to do that?

thanks

404 on wordpress multisite with permalinks

$
0
0
Hi,
I installed a wordpress multisite on nginx (basic configuration by webuzo) everything seem to work except when I activate permalinks. Then 404 Error appears except for homepage and backend.
Someone can help understand?
I'm a nginix absolute beginner.
Thanks,
Francesco

How to enable login wordpress to LAN users?

$
0
0
Hi,I just installed wordpress with nginx/mysql/php on Gentoo/Linux OS, as localhost at home.
I can edit wordpress web site only from local computer (where web server is installed).
I want to enable editing web site from other computers through LAN.
I can access web site through LAN, however can not login wordpress.
I get 'error_connection_refused' instead of login dialog box.
Please advise how enable web administration interfaces to LAN users?

Re: How to run wordpress on Gentoo/Linux?

$
0
0
Finally I found out how to solve this problem and here the info:
Need to 'modify the file /etc/vhosts/webapp-config and replace vhost_server="apache" by vhost_server="nginx".'
Then I followed https://wiki.gentoo.org/wiki/WordPress in particular the part of creating a database for wordpress by mysql. Here I got only index file of wordpress - so need to this line to /etc/nginx/nginx.conf in order to have GUI interface of wordpress:
'index index.php index.html index.htm;' rather than just 'index index.html;'

Sitemap Subfolder

$
0
0
Hi, I need configure sitemap with subfolder. See my configuration example:

server {
listen 80;

root /usr/share/nginx/html/example.com;
index index.php index.html;

server_name example.com www.example.com;


location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}


But the problematic site is example.com/subfolder

I make a test, configuring a new virtual host and adding the ip server and fake dns in my hosts file:

This setting works! But only at the site at the root. I tried adding the subfolder before / sitemap, but does not work!


server {
listen 80;

root /usr/share/nginx/html/example.com/subfolder;
index index.php index.html;

server_name example.com fake.example.com;

location ~ ([^/]*)sitemap(.*)\.x(m|s)l$ {
rewrite ^/sitemap\.xml$ /sitemap_index.xml permanent;
rewrite ^/([a-z]+)?-?sitemap\.xsl$ /index.php?xsl=$1 last;
rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
rewrite ^/news-sitemap\.xml$ /index.php?sitemap=wpseo_news last;
rewrite ^/locations\.kml$ /index.php?sitemap=wpseo_local_kml last;
rewrite ^/geo-sitemap\.xml$ /index.php?sitemap=wpseo_local last;
rewrite ^/video-sitemap\.xsl$ /index.php?xsl=video last;
}

location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}


}

Nginx reverse proxy with iis login page problems

$
0
0
I've asked this question on serverfault, where there is a +50 bounty on it currently.

http://serverfault.com/questions/754351/what-is-a-correct-ways-to-allow-login-to-an-iis-site-through-a-reverse-proxy/755659#755659

Basically, when I set up my reverse proxy, it works fine on pages without logins through iis, but if I have a site with iis login (the popup login similar to sharepoint's login), it just continuously asks for the login. There's no failed login attempt in the logs. I have all error logs listed in the serverfault question. Any help is appreciated. If I get a solution on serverfault, I will post the full question, and answer here.

Enable wildcard domains while disabling subdomains

$
0
0
I have a one-click WP install strictly for parking domains for sale using a highly regarded plugin/theme that will display an offer form for any domain pointing at the server provided there is a DNS entry.

If the server block specifies "server_name _;" it works. However, you can create a subdomain just by visiting it such as pigglywiggly.example.com/

Is there a way to allow the primary domains by wildcard but not allow subdomains? I became suspicious when I saw eliminate-bacterial-vaginosis.example.com in my stats.

Thanks in advance for any solutions or suggestions.

Re: Enable wildcard domains while disabling subdomains

$
0
0
I think 'server_name www.example1.com example1.com www.example2.com example2.com;' is what you want.

Re: hiding php parameters

Nginx + Owncloud + FastCgi = FastCGI sent in stderr: "Primary script unknown"

$
0
0
Edit: I tried to use bbcode here to make my post more readable, but it seems not to work...

Hey,

The Owncloud Guys suggested to post about my problem here, because i experience some error when working with nginx and fastcgi.
On my owncloud installation, nginx's error log is spammed by the following error:

[code]
"FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: MY IP, server: MY DOMAIN, request: "GET /core/img/actions/history.svg HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "MY HOSTNAME/DOMAIN", referrer: "MY DOMAIN"
[/code]

The path after "GET" varies between the above and: "GET /core/img/actions/settings.svg", "GET /settings/img/users.svg" and multiple other .svg files. Sometimes, there is even a .php file in it, but most of the time it is an .svg.

Everything works fine, and the error does only occur when accessing OC with my browser, not when i try to sync it with FolderSync on my Android phone. I even could not observe the error when syncing with the Windows client...so it seems to be a problem with web access. I can browse the web interface, but certrain buttons are missing. And of course, the error quickly fills up my log.

My config looks as following: (Note, Owncloud is installed in a subdirectory, /srv/www/owncloud)

[code]
upstream php-handler {
server unix:/var/run/php5-fpm.sock;
}

server {
listen MY IP:4433 ssl;
server_name MY DOMAIN;

ssl_certificate /etc/ssl/owncloud/owncloud_full.crt;
ssl_certificate_key /etc/ssl/owncloud/owncloud.key;
ssl_dhparam /etc/ssl/owncloud/dhparam.pem;

ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/ssl/owncloud/comodo_full_chain.pem;
resolver DNS SERVERS valid=300s;
resolver_timeout 10s;

ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
ssl_prefer_server_ciphers on;
ssl_trusted_certificate /etc/ssl/owncloud/comodo_full_chain.pem;
resolver 95.129.51.51 80.244.244.244 valid=300s;
resolver_timeout 10s;

ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
ssl_ciphers *LIST OF SECURE CIPHERS*;

ssl_session_timeout 10m;
ssl_session_cache off;
ssl_session_tickets on;
ssl_session_ticket_key /etc/nginx/ticketkey;

# Add headers to serve security related headers
add_header Strict-Transport-Security 'max-age=15768000; includeSubDomains; preload' always;
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;

# Path to the root of your installation
root /srv/www;

# set max upload size
client_max_body_size 10G;
fastcgi_buffers 64 4K;

# Disable gzip to avoid the removal of the ETag header
gzip off;

index index.php;
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;

rewrite ^/.well-known/carddav /remote.php/carddav/ permanent;
rewrite ^/.well-known/caldav /remote.php/caldav/ permanent;

# set max upload size
client_max_body_size 10G;
fastcgi_buffers 64 4K;

# Disable gzip to avoid the removal of the ETag header
gzip off;

index index.php;
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;

rewrite ^/.well-known/carddav /remote.php/carddav/ permanent;
rewrite ^/.well-known/caldav /remote.php/caldav/ permanent;

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location ~ ^/(build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}

location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location ~ ^/(build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}

location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}

location / {

#include /etc/nginx/naxsi.rules;
rewrite ^/remote/(.*) /remote.php last;
rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;
try_files $uri $uri/ =404;
}

## This is for naxsi ##
# location /RequestDenied {
# return 418;
# }

location ~ \.php(?:$|/) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS on;
fastcgi_param modHeadersAvailable true;
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
}

# Adding the cache control header for js and css files
# Make sure it is BELOW the location ~ \.php(?:$|/) { block

location ~* \.(?:css|js)$ {
add_header Cache-Control "public, max-age=7200";
# Add headers to serve security related headers
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
# Optional: Don't log access to assets
access_log off;
}


location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|swf)$ {
access_log off;
}
}
[/code]


So as you can see, this is the nginx config taken from the 8.2 documentation with SSL modifications. It is rated A+ on Qualys and everything works fine...but my error log is filled quickly by the "primary script unknown" error.

I've searched until page 4 on google (which means that i am truly desparate ;)), but i could not find a solution to my problem. Most of the times, some people suggested to move the "root" directive out of the location folder etc, but this is the case in my config...

Nginx seems to pass the wrong location to php5-fpm, becauxe php always looks into /srv/www/FILE and not into /srv/www/owncloud/FILE...

I would be glad if anybody had an idea to solve my problem...thank you in advance!

Lua timer and ngx.location.capture

$
0
0
Hello, how can I use ngx.timer.at and ngx.location.capture in same location ?

I trying some code but I get error !

rewrite_by_lua '
local delay = 1 -- in seconds
local dogs = ngx.shared.dogs

local status = dogs:get("Status")
if status == nil then
dogs:set("Status", 1)
end

local new_timer = ngx.timer.at
local log = ngx.log
local ERR = ngx.ERR
local check

check = function(premature)

if not premature then
local ok, err = new_timer(delay, check)
if ok then
if dogs:get("LuaChannels") == "stop" then
res = ngx.location.capture("/channel-stop?ch=1258")
dogs:set("LuaChannel", res.body)
dogs:set("LuaChannels", "")
end
return
end
end
end

local ok, err = new_timer(delay, check)
if ok then
if dogs:get("LuaChannels") == "stop" then
res = ngx.location.capture("/channel-stop?ch=1258")
dogs:set("LuaChannel", res.body)
dogs:set("LuaChannels", "")
end
return
end
';

On first call location the ngx.location.capture("/channel-stop?ch=1258") is working but not on next and I get error to error on log file

[error] 3756#4204: lua entry thread aborted: runtime error: rewrite_by_lua(nginx.conf:74):22: API disabled in the context of ngx.timer
stack traceback:
coroutine 0:
[C]: in function 'capture'
rewrite_by_lua(nginx.conf:74):22: in function <rewrite_by_lua(nginx.conf:74):15>, context: ngx.timer, client: 127.0.0.1, server: 0.0.0.0:8080

So I need to use timer when i seted dogs:get("LuaChannels") to start ngx.location.capture() and after that to reset functions until next call via dogs:get("LuaChannels") !?

I hope you are understand what I want .

Re: Enable wildcard domains while disabling subdomains

$
0
0
That's going to be more than inconvenient, that is impractical. There are 300+ domain names for sale, with many removed or added every day. By having the wildcard I don't have the 300+ domains actually in the config file, I just need to point the DNS to the IP#.

What I am asking is that every subdomain, even www, is not allowed on the HTTP port, such that the wildcard recognizes example.com but returns a 404 on requests for test.example.com, ssl.example.com and mail.example.com (mail, in fact, is handled by gmail, so no MX record is really necessary, but these are "hits" and "visits" I'm finding in my statistics log for the plugin). But example.com can be visited and the template for making an offer on just that domain is shown.

Perhaps I am not asking the question right either. If someone creates 4rrzz.com79wmwww.google.example.com (which only displays said template), what harm is there? Though it could be visited again, could it actually be abused? There are no pointers in var/www/html/wp-content/ showing such a "place."

Real IP problem on my load balancer in TCP mode on my servers

$
0
0
Dear All,

I am a System Admin from India and using nginx as load balancer since some time.

I have few web servers which I am load balancing using nginx and they are working fine. I use --with-http_realip_module and

location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://ws1;
}

and is working absolutely fine.

I have a situation here now I want to load balanced my email server using TCP support of nginx and I am having issue getting the real IP from my load balancer in TCP mode to my load balanced servers.

On the backend servers, I am getting the IP address of load balancer but not the actual client IP which I wanted it to be passed to them.

I am referring the website: https://tipstricks.itmatrix.eu/tcp-load-balancing-for-email-servers-with-nginx and able to load-balanced the traffic except the Real IP.

Please help.

Thanks in advance.

Re: Reverse Proxy Forward

$
0
0
stream {

upstream backend {
server backend1.example.com:12345;
}

server {
listen 12345;
proxy_pass backend;
}
}

How to get access to a response header fields in a proxy_pass case

$
0
0
Hi,
I am trying to get access to a custom response header, save it into a variable, and get rid of it so that it will not be proxied back to the client. That variable is then used in the access logs.
Unfortunately, the following doesn't seem to work:

server {
listen 142.133.151.129:8090 default;

##Intial values for calculated access log variables
set $cache_status "-";
set $destination_addr "-";

location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://my_upstream_server;

proxy_http_version 1.1;

proxy_max_temp_file_size 0; #size of the temp file when response doesn't fit in buffer

#Setting access log variables
if ($sent_http_x_cache = "HIT") {
set $cache_status "HIT";
}
if ($sent_http_x_cache != "HIT") {
set $cache_status "MISS";
}
set $destination_addr $sent_http_x_destination;
# now get rid of these response header fields
set $sent_http_x_destination "";
set $sent_http_x_cache "";
}

I am getting empty values for $sent_http_x_destination and $sent_http_x_cache.

Here is the curl request and response:

[root@CL10-RH66-lmchaka ~]# curl -Ov --range "100-1000000" http://142.133.151.129:8090/ao3/vod/soccer/worldcup2014/final1
< HTTP/1.1 206 Partial Content
< Server: openresty/1.9.3.1
< Date: Tue, 16 Feb 2016 22:25:32 GMT
< Content-Type: application/octet-stream
< Content-Length: 999901
< Connection: keep-alive
< Accept-Ranges: bytes
< Age: 660
< ETag: "3833945841"
< Content-Range: bytes 100-1000000/94371840
< X-Cache: HIT
< X-Destination: 142.133.151.94
<

I would appreciate if someone can help and provide a determistic way to see the response header fields and store them into variables.

Thanks

Re: Enable wildcard domains while disabling subdomains

$
0
0
Hi. Would something like this work for you?

server {
listen 80 default;
server_name _;
return 200 'default\n';
...
}

server {
listen 80;
server_name ~^.*\..*\..*$;
return 444;
}

Testing with curl...

[root@nginx-splunk conf.d]# curl -H "Host:example123.com" localhost
default

[root@nginx-splunk conf.d]# curl -H "Host:example456.com" localhost
default

[root@nginx-splunk conf.d]# curl -H "Host:subdomain.example456.com" localhost
curl: (52) Empty reply from server

[root@nginx-splunk conf.d]# curl -H "Host:subdomain.example123.com" localhost
curl: (52) Empty reply from server

--Kevin
@webopsx

.htaccess codes Conversion

$
0
0
Hi,

I'm using NGINX 1.8.1


how can i use replacement code of :

<FilesMatch "\.(mov|mp4|mp3|jpg|pdf)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>

Progress module with 1.8.x / 1.9.11

$
0
0
Hello,

I'm wondering if anyone is successfully running the progress module with 1.8.x or the latest 1.9.11 ?
https://github.com/masterzen/nginx-upload-progress-module

I would like to confirm if it is working for anyone (or not) on the 1.8/1.9 version before ticketing for developer support.

I have the module working with 1.6.x but I went with updated versions of Nginx and have this issue.

With 1.9.11 the module is returning the same values for received and size.
This is a similar problem as https://github.com/masterzen/nginx-upload-progress-module/issues/36

There was a reported fix but the Nginx version referenced is 1.4 and the module works with 1.6.x
The issue prior related to client_body_buffer_size.

How to redirect to another web with same domain

$
0
0
Hi!

It's possible to have a domain and when a user for a specific country connect to that web, nginx redirect to another web but without change the domain.

for example:

i have tha domain www.example.com and if an users open that web in America they see a youtube.com but the domain still be www.example.com and if users connect from Europa the see the real web.

Regards.
Viewing all 4759 articles
Browse latest View live


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