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

Nginx as reverse proxy for Exchange ActiveSync with certificate authentication (no replies)

$
0
0
Hi,
I try to configure Nginx as reverse proxy for Exchange ActiveSync with certificate authentication.
Owa and other services work perfectly. In addition, if I use password authentication for Exchange ActiveSync, it also works.
But if I try to use certificate authentication on Exchange, Nginx doesn't work.
Usually I get the error:
2014/11/25 14:33:33 [error] 14524#0: *37 upstream prematurely closed connection while reading response header from upstream, client: 145.45.218.140, server: mail.domen.ru, request: "OPTIONS /Microsoft-Server-ActiveSync HTTP/1.1", upstream: "https://172.16.11.14:443/Microsoft-Server-ActiveSync", host: "mail.dome.ru"

I use config like this:


server {
listen 443;
ssl on;
ssl_certificate /etc/ssl/nginx/mail.dome.ru.crt;
ssl_certificate_key /etc/ssl/nginx/mail.dome.ru.open.key;
ssl_session_timeout 5m;

server_name mail.dome.ru;

location / {
return 301 https://mail.dome.ru/owa;
}

proxy_read_timeout 360;
proxy_pass_header Date;
proxy_pass_header Server;
#proxy_pass_header Authorization;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

location ~* ^/owa { proxy_pass https://exch1.test.local; }
location ~* ^/Microsoft-Server-ActiveSync { proxy_pass https://exch1.test.local; }
location ~* ^/ecp { proxy_pass https://exch1.test.local; }
location ~* ^/rpc { proxy_pass https://exch1.test.local; }

error_log /var/log/nginx/owa-ssl-error.log;
access_log /var/log/nginx/owa-ssl-access.log;

nginx always rederict me to my internal ip (no replies)

$
0
0
Hello everybody,

im using nginx with owncloud on my raspberry pi. Under "sites available -> default" i've set it up like this.

server {
listen 80;
server_name 192.168.1.114;
return 301 https://$server_name$request_uri; # enforce https
}

server {
listen 443 ssl;
server_name 192.168.1.114;

ssl_certificate /etc/nginx/cert.pem;
ssl_certificate_key /etc/nginx/cert.key;

# Path to the root of your installation
root /var/www/owncloud;

......


Now, i've registered a no-ip domain, forwarded the ports etc. that i can access my cloud from anywhere.

I've changed the "server_name" to my no-ip domain and restarted nginx. Now when i type in "mynoipdomain.whatever.com" in my browser, it always rederict me to "192.168.1.114". Therefore im not able to access it over the internet.

What do i have to do that i can access my server from the internal ip when im in LAN (that it sync the files faster), but i also want to get access to it over my no-ip domain.

Any ideas?

How to set response from rewrite_by_lua_file directive (2 replies)

$
0
0
I have a rewrite_by_lua_file directive where I lookup a key supplied as a header in the original request, in a shared lookup table. If found, I pass as a header the value mapped to the original key. If not, I return a specific status code.

So in my nginx.conf file I have something like this:

location /start
{
rewrite_by_lua_file key_lookup.lua;
proxy_pass http://127.0.0.1:8080/start;
}


And my key_lookup.lua is attached.

So I am trying to use ngx.say to set the response body to a specific JSON content when I return 401 Unauthorized, with no luck (the status code returned is what I expect, but the response body is empty). I have also tried using ngx.print.

Is there another way to achieve this?

NGINX: Disk write spike and/or not enough workers error from sudden surge in traffic causing 500 errors (1 reply)

$
0
0
I have been trying to diagnose an issue we have on our production servers. We have a server running NGINX as a load balancer which splits requests between four application servers. At least a few times throughout the day while testing the site we get 500 errors that only last for a few seconds.

Looking through the error logs and access logs, as well as graphs on new relic and our hosting service I have noticed a few things...

A few times a day there are sudden and massive jumps in disk write on the load balancer. I'm pretty sure this is due to so many requests being written to the access log in a short period of time (yesterday it was over 300 MB, most of which came in a very short period of time)... It's almost as if a bunch of requests are being blocked, piled up and then spit out simultaneously.

Also, once in a while I get a "768 worker connections is not enough..." in the error logs. I'm guessing I just need to raise this limit, but I'm not sure by how much, or how I can find the max that will work.

I'm not sure if these two issues are connected, or if either one is causing our random 500 errors.

Any insight or advice on further diagnosis would be greatly appreciated!

HTTP caching and ETAG header (no replies)

$
0
0
Hi,

After a lot of unsuccessful research, I'm wondering if it's possible to use nginx cache function to check data freshness it contains using etag attribute in the header.

This scenario is easier to explain with a diagram, please see attachment.

Do you think this use case is feasible ?

Thank you and sorry for my english :s

nginx rewrite? try_files? how to try_files if script returned nothing or 404 or whatever? (no replies)

$
0
0
I have two files in perl and php e.g script.pl and script.php

php is listening on 6060.

how can i make it such that if script.pl returns nothing (or zero), it will be diverted to script.php?

location ~* "^/" {
rewrite ^/(.*) /script.pl?$1;
try_files $uri /script.php?$1 /index.html;

set $server_used 127.0.0.1:6060;
proxy_pass http://$server_used;
break;
}
basically i'm clueless how i can make script.php "be tried" if script.pl returns nothing or zero or 404 or whatever? can anyone help?

rtmp-module, push livestream chunk_size and record on (no replies)

$
0
0
I setup an nginx server compiled with the rtmp-module and I am currently just using push to push my gaming livestream to both hitbox and twitch. I noticed some people use
[code]chunk_size 4096[/code]
and some people use
[code]chunk_size 8192[/code]
I tried googling the nginx chunk_size but didn't get many results. Can someone please tell me what this setting does, I would like to optimize the use of nginx with the rtmp-module the best I can.

Then my second question is how to enable nginx to store a local copy of what it's pushing. I tried to enable
[code]record on[/code]
but then nginx fails to start

Is there a way to cache only GET Ajax request? (1 reply)

$
0
0
Usually I have in nginx config rules which does not allow cache all XMLHttpRequest map $http_x_requested_with $nocache_01 { default 0; XMLHttpRequest 1; }

Is there a way to cache only GET Ajax request?

Br,
Rostyslav

Replace paths from URI (no replies)

$
0
0
I want to rewrite

https://mydomain.com/app#/listClients?token=e34f14bae3fb68ecb042328f1b5a6d9

to

https://mynewdomain/new-path#/listClients?token=e34f14bae3fb68ecb042328f1b5a6d9

ie., I want to replace mydomain with mynewdomain and I want to replace app# with new-path#

I tried

rewrite ^/app#/(.*) https://mynewdoain.com/listClients#/$1 permanent;

error help me look (no replies)

$
0
0
visit:l27.0.0.1/test.jsp is ok,but:

visit:l27.0.0.1 skip to>>http://127.0.0.1/mem/index.jhtml
hint:404 Not Found

visit:http://172.16.0.103:8080 skip to>>http://127.0.0.1:8080/mem/login.jhtml is visit normal ,ok

see index.jsp
[root@gavin mem]# more index.jsp
<%@ include file="/com/taglibs.jsp"%>

<c:redirect url="/mem/index.jhtml"/>

more nginx.conf

user www www;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log info;
pid /usr/local/nginx/nginx.pid;

google_perftools_profiles /tmp/tcmalloc;

worker_rlimit_nofile 65535;

events
{
use epoll;
worker_connections 65535;
}

http
{
include mime.types;
default_type application/octet-stream;
#charset gb2312;



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;


server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 300m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
server_tokens off;

client_body_buffer_size 512k;
proxy_connect_timeout 5;
proxy_send_timeout 60;
proxy_read_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
# fastcgi_connect_timeout 300;
fastcgi_intercept_errors on;
# fastcgi_send_timeout 300;
# fastcgi_read_timeout 300;
# fastcgi_buffer_size 64k;
# fastcgi_buffers 4 64k;
# fastcgi_busy_buffers_size 128k;
# fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;

#limit_zone crawler $binary_remote_addr 10m;

server
{
listen 80;
server_name web_1.fohow.com;
index index.jsp index.html index.do;
root /usr/local/tomcat/webapps/www;
#limit_conn crawler 20;
if (-d $request_filename)
{
rewrite ^/(.*)([^/])$ http://$host/$1$2/ last;
}

location ~ \.(jsp|jspx|do)?$ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:8080;
proxy_redirect default;
}

location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
}
}

please tell me Wrong and how to do ?

how limit download speed in directadmin Nginx (no replies)

$
0
0
Hello


I install directadmin (CB2) + Nginx and i want to limit the speed download .

How i can do it ?

Please help me

Thanks

GetSimple CMS with NGINX (no replies)

$
0
0
Hi,
I'm trying to secure GetSimple CMS, but I'm not able to disallow the download of files in the /admin/ folder, when using tools like curl or wget.

---------------------------
The server runs archlinux with php-fpm.

server configuration block in nginx.conf:
server {
index index.php index.html index.htm;
server_name example.com;
listen 80;
root /path/to/getsimplecms;
include php.conf;
# Stop deep linking or hot linking (except for own hosts)
location /uploads/ {
valid_referers none blocked <some hosts ...>
if ($invalid_referer) {
return 403;
}
}
location ~ \.(xml|xml\.bak)$ {
deny all;
}
location ~ /\. {
deny all;
}
location /admin/ {
auth_basic "Restricted";
auth_basic_user_file /path/to/some/htpasswd;
}
location = /sitemap.xml {
allow all;
}
}

php.conf:
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
include fastcgi.conf;
}

fastcgi.conf:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS $https if_not_empty;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
---------------------------

auth_basic is working as expected for the /admin/ location ..but I still can download files from that folder.

i.e.
$ wget http://example.com/admin/settings.php
--2014-12-06 21:56:06-- http://example.com/admin/settings.php
Resolving example.com (example.com)... XX.XX.XX.XX
Connecting to example.com (example.com)|XX.XX.XX.XX|:80... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: index.php?redirect=/admin/settings.php? [following]
--2014-12-06 21:56:06-- http://example.com/admin/index.php?redirect=/admin/settings.php?
Reusing existing connection to example.com:80.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘settings.php’

0K .. 308K=0.009s

2014-12-06 21:56:06 (308 KB/s) - ‘settings.php’ saved [2234]
----

I'm really new to nginx and already tried different things to avoid that "index.php?redirect=/admin/.*\.php" can be processed... but nothing worked so far, please help!

How to configure nginx for fastCGI (not php) (3 replies)

$
0
0
Hi all,

sorry if my request seems stupid but I am completely a newbie on nginx.
I tried to find the solution by myself and searching on this forum and on internet but I had no luck.

Basically I have an embedded webserver (developed with freepascal, it is an executable running on localhost:9000) that is developed to:
1) reply to commands on "/". Request to this usually are related to "static" files (templates that are modified on the fly and send)
2) reply to a series of REST uri (like "api/users", "api/clients" and so on).

Now, I changed the code a bit and transformed the webserver in a fastCGI because I want to take advantage of nginx speed and stability.

How should the configuration be?

I've tried several things, but nothing worked.
But again, I am a newbie.

Could you help me, please?

Mirko

Nginx RewriteRule Help me please !!!‏ (no replies)

$
0
0
Hi, I purchased this script in codecanyon.net (http://codecanyon.net/item/mouse-media-script/7773254) But permalinks not working. I've added the script .htaccess files to topic. Please help me.

Thanks.

Я люблю Nginx

Ahmet Akdeniz, Regards.

My htaccess file:

DirectoryIndex index.php
RewriteEngine On

RewriteRule ^1aWtPdaeKwG(.*)-(.*) /themes/$1/files.php?type=css&files=$2
RewriteRule ^00cv6P016Bz(.*)-(.*) /themes/$1/files.php?type=javascript&files=$2
RewriteRule ^images_(.*)/(.*)(.*) /themes/$1/images/$2 [NC,L]

RewriteRule ^rss$ ./sources/rss.php
RewriteRule ^sitemap.xml$ ./sources/sitemap.php

RewriteRule ^gag/([^/.]+)/?$ index.php?view=news&id=$1 [NC,L]


RewriteRule ^gag/delete/([^/.]+)/?$ index.php?view=delete_news&news_id=$1 [NC,L]

RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?view=cat&cat=$1 [NC,L]

RewriteRule ^view/([^/.]+)/?$ index.php?view=$1 [L]
RewriteRule ^view/([^/.]+)/([0-9]+)?$ index.php?view=$1&background=$2 [L]
RewriteRule ^view/([^/.]+)/([^/.]+)?$ index.php?view=$1&action=$2 [L]
RewriteRule ^view/([^/.]+)/([^/.]+)/([0-9]+)?$ index.php?view=$1&action=$2&page=$3 [L]
RewriteRule ^view/([^/.]+)/([^/.]+)/([^/.]+)?$ index.php?view=$1&action=$2&subaction=$3 [L]
RewriteRule ^view/([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)?$ index.php?view=$1&action=$2&subaction=$3&id=$4 [L]
RewriteRule ^u/(.*)/([^/.]+)/?$ index.php?view=account&action=profile&profile=$1&subaction=$2 [L]
RewriteRule ^u/(.*) index.php?view=account&action=profile&profile=$1 [L]
RewriteRule ^user/settings?$ index.php?view=account&action=settings [L]
RewriteRule ^user/settings/([^/.]+)?$ index.php?view=account&action=settings&subaction=$1 [L]
RewriteRule ^view/meme/action/([^/.]+)?$ index.php?view=meme&action=$1 [L]
RewriteRule ^view/meme/action/create/(.*)?$ index.php?view=meme&action=create&t=$1 [L]
RewriteRule ^view/meme/action/create/image/display(.*)?$ index.php?view=meme&action=create&t=$1 [L]
RewriteRule ^view/meme/action/show/c/([^/.]+)?$ index.php?view=meme&action=show&c=$1 [L]
RewriteRule ^view/upload/meme/post_url/num/([^/.]+)?$ index.php?view=upload&post_url=$1 [L]
RewriteRule ^member/delete/?$ index.php?view=delete_account [L]
RewriteRule ^pages/([^/.]+)?$ index.php?view=pages&id=$1 [L]

RewriteRule ^([^/.]+)/([^/.]+)/?$ index.php?view=news&cat=$1&id=$2 [NC,L]

Rewrite location and then proxy_pass (1 reply)

$
0
0
I'm having some difficulties rewriting a location to https, then asking if a specific cookie or IP is matched and then pass it to a http backend. For example, I need the /api location rewritten to https since the whole domain is just http and don't may be rewritten completely to https. My intention is something like this:

location ^~ /api {

rewrite https://$http_host$request_uri; (rewrite the location to https)

if ($iporcookiematches != 1) { (and then check if the ip or cookie matches)
return 403;
}

proxy_pass http://backend;
}

Does it make sense? Is it somehow possible?

Cheers,
Szop

Can nginx route to oneself using different domains? (no replies)

$
0
0
Hello,

I'm trying to do A/B testing with nginx, and let's say I have one nginx instance on a host having three different domains, nginx-a, nginx-b, and nginx-c.

- /etc/hosts
---
192.168.50.10 nginx-a nginx-b nginx-c;
---

Now what I want to do is to proxy requests from a domain nginx-a to nginx-b or nginx-c using some weighted load balancing method. In the following example, the client request first should be sent to nginx-a, then 95% of requests are distributed to nginx-b (and finally, to backend-b) and 5% of them are to nginx-c (backend-c)

- nginx.conf
---
upstream backend-a {
server nginx-b:5000 weight=95;
server nginx-c:5000 weight=5;
}

upstream backend-b {
server server-b-1:9000;
server server-b-2:9000;
server server-b-3:9000;
}

upstream backend-c {
server server-c-1:9000;
server server-c-2:9000;
server server-c-3:9000;
}

http {
server {
listen 5000;
server_name nginx-a;
location /test {
proxy_pass http://backend-a;
}
}

server {
listen 5000;
server_name nginx-b;
location /test {
proxy_pass http://backend-b;
}
}

server {
listen 5000;
server_name nginx-c;
location /test {
proxy_pass http://backend-c;
}
}
}
---

My questions are:

1. Is it possible route to oneself as an upstream server using different domains?
2. (If possible) Does it cause any performance degradation compared with general proxying (required http connections are doubled, etc)?
3. (If not possible) Are there any alternative way of using weight for a group of upstreams?

Help with rewrite(loop error) (no replies)

$
0
0
Hello my dear friends

I have some problem with rewrite.

I have example.com

I need 301 redirect:
example.com/index -> example.com
example.com/index.html -> example.com
example.com/about.hrml -> example.com/about
example.com/contacts.php -> example.com/contacts

Please help!

I try to do somthing like this:
rewrite ^/index.html$ $scheme://$host permanent;
rewrite ^(/.+)\.html$ $scheme://$host$1 permanent;

But i have redirection loop error

Web page degraded when root path is changed (no replies)

$
0
0
Hi,
I'm setting a wordpress up with nginx.
Everything's seems ok :
- server is up
- phpinfo() test is ok
- the worpress install routine is showing up
The only trouble is the root statement in the web server conf file.
If I use :

[/etc/nginx/sites-available/wordpress]
server{
root /var/www;
index index.php
server_name myweb.net
...
}
I can reach the service using http://myweb.net/wordpress, now I want wordpress to be designated as the root folder.
Here's the change :

[/etc/nginx/sites-available/wordpress]
enter code here
server{
root /var/www/wordpress;
index index.php
server_name myweb.net
...
}

Broken! The web page http://myweb.net is only displaying basic html data, no pics, no css, ... ugly.
No errors reported in /var/log/nginx/access.log
nginx version: nginx/1.2.1
What's wrong?

Internal server error Using Joomla (no replies)

$
0
0
Hello, I'm setting up a joomla website using nginx 1.2.1-2.2 on Raspbian wheezy. The homepage is displayed properly. But if I add another site (called "collection") and click on the menue button I got a 500 internal server error.

Error log says:
2014/12/16 17:20:42 [error] 14546#0: *45 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: xxxx, server: smtagore.de, request: "GET /index.php/collection HTTP/1.1", host:"xxxx:8001", referrer: "http://xxxx:8001/index.php"

I've checked relvant posts since hours but can't fix it.

Any idea where to start?

I gladly give more information, whatever is needed.

Best,
AndRi22

anonymous GET all others to be authentificated (no replies)

$
0
0
Hi Guys I am stuck with an issue here, I have a web page that I need to allow anonymous views but not post/put/etc.
Is that posible with nginx ? could this be a webdav thing?

Currently I have this config, which is not really working, it is asking for a password all the time.

location /java/stable {
root /storage/docs/java/stable;
autoindex on;
dav_methods PUT DELETE MKCOL COPY MOVE;
dav_ext_methods PROPFIND OPTIONS;
create_full_put_path on;
dav_access group:rw all:r;
auth_basic "Restricted";
auth_basic_user_file /srv/.webdav_htpasswd;
Viewing all 2931 articles
Browse latest View live


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