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

How to compare in the if block. (no replies)

$
0
0
Hello.

I need to redirect a request depending on the request_length.

If the request_length is less than or equals 1000 bytes it's redirected to upstream X.
If the request_length is greater than 1000, then it's redirected to upstream Y.

Since the rewrite module doesn't support "less than", "greater than" comparison "If ($request_length > 1000) { ... }" is impossible.
Who can give me a hint how I could extricate myself?

Thanx.

Can I cache the GeoIP database to disk instead of memory? (no replies)

$
0
0
This is supported on mod_geoip for Apache to reduce memory usage. Is there a way to do this in Nginx so I can use the GeoIP city database without it taking up a ton of RAM?

location, alias, php and static files (no replies)

$
0
0
Hello,

i've a main domain configured on my dedicated server, the access is only by SSL (redirect http to https).

Here is my only vhost http://p.ngx.cc/5c ( /etc/nginx/sites-available/domaintld )

My root directory is /opt/octopress/public and serve only static files (html/css/pictures/js/etc...) and everything is OK !

I now want to add a location https://domain.tld/piwik in this vhost, the "root" directory of piwik is /var/www/piwik .

I tried this in my vhost:

location /piwik {
alias /var/www/piwik;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

# With php5-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

PHP is interpreted but static files are not ! This location takes the root directory /opt/octopress/ and deserve static files with wrong path.

For example:

/opt/octopress/public/piwik/plugins/Zeitgeist/images/dashboard_h_bg_hover.png is not found !!

The right location is /var/www/piwik/plugins/Zeitgeist/images/dashboard_h_bg_hover.png !!

What am i doing wrong? Thank you for any help!!

raumin

if and proxy_pass_header (no replies)

$
0
0
According to cookie variable I need to make proxy_pass_headers, but proxy_pass_header directive is not allowed in "if". How to resolve this problem?

I tried to do this with help of predefined locations. But for colling predefined location I didn't found any opportunity except error_page 302 = @location; return 302. In this case GET requests are working fine, but on POST request I received error "upstream prematurely closed connection while reading response header from upstream". On error code 404 all working normal, but this is bad practice, I think.

Thank You for any suggestions!

Mail servers' proxy (imap+pop3+smtp and WEBMAIL) (no replies)

$
0
0
Hello,
I'm trying to configure a full proxy for my mailservers.
With full, I mean for all protocols.

We have, for example, 2 mail servers:
zimbra (imap,pop3,smtp,webmail)
linux+roundcube (imap, pop3, smtp, webmail)

Using MySQL I'm able to configure imap,pop3,smtp proxy: when a user connect to the proxy, my nginx script checks on a database where to redirect the login. If to the Zimbra server or to the linux server.

The problem is with webmail: is there some way to redirect http to zimbra webmail or to roundcube, depending on the username? Do I have to create a login page and then use webmail's api to redirect the login?

What I want is to give a single hostname to users, for example webmail.mydomain.com, and then let nginx redirect users to the right webmail how it does for imap,pop3 and smtp.

Thanks!
Andrea

Optimize nginx (fastcgi) for Wordpress Picture Blog (no replies)

$
0
0
down vote favorite


I recently rent a vServer and now I am playing around with nginx, fastcgi cache and my wordpress setup. It's running pretty fast right now but in all speed test I came across my js and css files. Is there some kind of minifying implemented in nginx I could use? Also my pictures galleries do have a lot of pictures, is there something else I could use to increase the performance? (all pictures are stripped down to a minimum file size already)

This is my nginx.config:

user www-data;
worker_processes 1;
pid /var/run/nginx.pid;

events {
worker_connections 768;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 10;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

and my host file:

fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=MYAPP:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";

server {
listen 80;
root /var/www/blog;
index index.php;
server_name IPADRESS;
location / {
try_files $uri $uri/ /index.php?$args;
#Cache everything by default
set $no_cache 0;
#Don't cache POST requests
if ($request_method = POST)
{
set $no_cache 1;
}
#Don't cache if the URL contains a query string
if ($query_string != "")
{
set $no_cache 1;
}
#Don't cache the following URLs
if ($request_uri ~* "/(administrator/|login.php)")
{
set $no_cache 1;
}
#Don't cache if there is a cookie called PHPSESSID
if ($http_cookie = "PHPSESSID")
{
set $no_cache 1;
}
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ .php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_cache MYAPP;
fastcgi_cache_valid 200 60m;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)(\?ver=[0-9.]+)?$ {
expires 365d;
}
}

I don't want to install a plugin just for this stuff (keep Wordpress as simple as possible) so I am looking for the best basic setup for wordpress. (System: Debian Wheezy)

Cheers
Moritz

NginX - Wordpress under subfolder (no replies)

$
0
0
I'm having little problems with Nginx and Wordpress. We have not standard configuration where everything except defined folders and files will be sent to wordpress. And wordpress is in subdirectory /wordpress but it must behave like it's not. For now we managed to get this configuration working and here is part of it:

if ($request_uri ~ "^/(folder1|folder2|folder3|folder4)/") {
break;
}

if ($request_uri ~ "^/(file1\.ext1|file2\.ext2|file3\.ext3|file4\.ext4)") {
break;
}

if ($request_uri ~ "^/$") {
break;
}

if ($request_uri ~ "^/\?m\=[0-9]$") {
break;
}

rewrite ^/(.*)$ /wordpress/$1;

location ~ /wordpress {
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}

rewrite /wp-admin$ /wp-admin/ permanent;

location ~ ^/wordpress/wp-admin/ {
include /etc/nginx/settings/moderator-access.conf;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
}

rewrite ^/?(.*)$ /wordpress/index.php?$1;

try_files $uri $uri/ /index.php?$args;

# Handling PHP files
include settings/php-fpm.conf;
}

Problem with this config (except being complex :)) is that when someone goes to www.example.com/wp-admin/ it gives 404 blank page. But what's interesting if you type www.example.com/wp-admin/index.php everything works excellent. Doe's anyone have idea how to fix this?

P.S. We recently switched to Nginx and we are still struggling with it :) It's not easy after 7 years on Apache to switch :)

redirect and rewrite problem (no replies)

$
0
0
Hello, I have problem with with redirect and rewrite.

I wanted to redirect/rewrite http://users.domain.tld/user/foobar/ & http://users.domain.tld/~user/foobar

to

http://www.newdomain.tld ( not http://www.newdomain.tld/user/foobar/ or http://www.domain.tld/~user/foobar/ )

Thank you helping me.

peja

how to apply LIMIT_CONN after AUTH_REQUEST (no replies)

$
0
0
Hi,

i need to limit concurrent connection count, but not per IP as shown everywhere, but per a variable (user_id for example) set by auth_request_module

Example:

http {
limit_conn_zone $my_userid zone=peruser:40m;
}

server {
auth_request /auth;
auth_request_set $my_userid $upstream_http_x_userid;

location /auth {
...
}

limit_conn peruser 2;
}



.. could it be done somehow?

Thanks

1.5.10: spdy not being used at all here (1 reply)

$
0
0
after reading about 1.5.10 release.. i discovered SPDY.. i had not heard of it before.
so i built nginx with the spdy module and restarted the server.
i added spdy to the name of the server in the server config - next to ssl and default_server.
(my site is ssl only).

i thought that would be all i needed to do to activate spdy.
however, when i view my site using the firefox spdy test plugin (or using the spdycheck website) - they both show spdy is inactive.

anyone know why that would be?
thanks

Pass SSL Chain to Client (1 reply)

$
0
0
Hi,

We are set up a web Service with the Client Certificates as follow:

ssl on;
ssl_prefer_server_ciphers on;
ssl_protocols SSLv3 TLSv1;
ssl_ciphers DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:EDH-RSA-DES-CBC3-SHA:AES256-SHA:DES-CBC3-SHA:AES128-SHA:RC4-SHA:RC4-MD5;
ssl_certificate /etc/nginx/vhosts.d/ssl/bundle-cert.crt;
ssl_certificate_key /etc/nginx/vhosts.d/ssl/cert.key;
ssl_stapling on;
ssl_stapling_responder http://ocsp.xxxx.com/;
#ssl_stapling_verify on;
resolver 8.8.8.8;

ssl_verify_client optional;
ssl_verify_depth 3;
ssl_client_certificate /etc/nginx/vhosts.d/ssl/ClientCA.pem;

location / {
try_files $uri $uri /index.php;
}

location ~* \.php$ {
fastcgi_pass cifcgi;
include fastcgi_ssl.conf;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/path/to/public_html/$fastcgi_script_name;
fastcgi_param PLATFORM preview;
fastcgi_param VERIFIED $ssl_client_verify;
fastcgi_param DN $ssl_client_s_dn;
}
}

NGINX
nginx version: nginx/1.4.4
built by gcc 4.7.2 20130108 [gcc-4_7-branch revision 195012] (SUSE Linux)
TLS SNI support enabled
configure arguments: --prefix=/usr --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --with-http_ssl_module --error-log-path=/var/log/error.log --http-log-path=/var/log/nginx/access.log --user=nginx --group=www --with-pcre=/root/Download/pcre-8.34 --add-module=/root/Download/ngx_http_redis-0.3.7 --with-debug

OpenSSL 1.0.1e 11 Feb 2013

RESULTS:
Authentication works, Client Cert is accepted if valid.

PROBLEM:
Certificate Chain is not visible on the client side.

We are trying to achieve the same the Apache directive SSLOptions +ExportCertData does. The full Certificate Chain is available in SSL_CLIENT_CERT.

Any help will be much appreciated

nginx not executing php redirect script (no replies)

$
0
0
I have a website that was recently migrated from Cold Fusion to Wordpress. To ensure that old links were still valid, our developer wrote a redirect script that translates old URLs into new URLs.

I set up a virtual redirect, but for some reason old style URLs (e.g., page.cfm___BIG_NASTY_STRING__) get sent to the text of the php script or attempt to actually download the file - it doesn't execute.

Here's the relevant portion of my config file:


...
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTP_HOST $host;
include fastcgi_params;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found on;
}

#Redirects for old CFML-style links

location /page.cfm {
alias /legacy/redirect.php;
}

Does anyone have any idea how to get redirect.php to execute instead of just displaying or downloading?


Thanks,


David

nginx-naxsi with gzip_static (no replies)

$
0
0
Hi
Is there a package available for Ubuntu somewhere that has nginx-naxsi with gzip_static enabled/compiled in ?

/Henrik Schack

nginx + varnish (no replies)

$
0
0
Hi everyone!

I am trying to setup ngnix + varnish using this tutorial (http://ewan.im/900/10-million-hits-a-day-with-wordpress-using-a-15-server). Everything was going great until I installed Varnish and moved varnish to port 80 and nginx to 8080. At that point I started to get 404s from nginx complaining about /etc/nginx/html not being a directory. After this I added the directory and now I am getting 403's. Not sure what permissions need to be done or if this is the symptom of something else. This is my first nginx install. Any help would be great!

Thanks!

UPDATE:
I also posted a github issue around this here for more info: https://github.com/ewanleith/Wordpress-Server-Configuration-Files/issues/3

Help with weird URL parsing problem (no replies)

$
0
0
I am an nginx newbie. Apologies in advance for stupid questions.

I am running Wordpress on nginx on a linode....I made the switch for performance, and I have been thrilled.

I have one problem -- my setup will not handle any wordpress URL containing the characters "php"

For example

http://www.mysite.com/this-url-contains-the-characters-php.html --> 404

or

http://www.mysite.com/category/php/post-slug --> 404

etc

Any URL on my site that contains the characters "php" in the URL results in a 404 error.

I am baffled (no doublt because I am a newbie).

To make matters worse, searching for help using "php" in the Google search query makes it impossible to find anything -- there is just so much stuff about using PHP with nginx that you cannot sort through it all....

Anyway -- can you guys think of something to check?

Open to ideas.

Thanks,
Mark

Correct block syntax with ssl + varnish + www rewrite (1 reply)

$
0
0
Is it ok to have rewrites for www to non-www as if statements in each http and https server block rather than using a separate server block just for the rewrite as listed in the pitfalls page?

My current config looks like this:


server {
listen 127.0.0.1:8001;
server_name example.org www.example.org;
root /home/user/public;
index index.php
gzip_static on;
access_log /var/log/nginx/example.org_access.log;
error_log /var/log/nginx/example.org_error.log;
include conf.d/drupal.frag;

if ($host = 'www.example.org' ) {
rewrite ^/(.*)$ http://example.org/$1 permanent;
}
}

server {
listen 443 ssl;
server_name www.example.org;
root /home/user/public;
index index.php
gzip_static on;
access_log /var/log/nginx/example.org_access.log;

ssl_certificate /etc/ssl/certs/example.org.pem;
ssl_certificate_key /etc/ssl/private/example.org.key;
ssl_ciphers HIGH:MEDIUM:!aNULL:!aDH:@STRENGTH;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;

# require SSL for phpMyAdmin
include conf.d/phpmyadmin.frag;

include conf.d/drupal.frag;

if ($host = 'www.example.org' ) {
rewrite ^/(.*)$ http://example.org/$1 permanent;
}
}

Problem with nginx +Mariadb+Shopware (2 replies)

$
0
0
Hi

Iam new at nginx and i want to set up a Shopware with mariadb and nginx but everytime i try to install it says 405 Not Allowed nginx/1.1.19

its running on a VM created with kvm
so what i am trying now is to rebuild everything because i messed up the settings pretty much :D i will have more details after i have set up everything again. runnung Ubuntu 12.04 LTS. If someone knows why i get always this error please help :D if you need anything just ask i will try to answer. Iam quite new to the whole server stuff.

WebDAV, UTF-8, проблемы с русскими буквами у клиентов (no replies)

$
0
0
День добрый!
Обнаружилась проблема с чтением и отображением русских букв при доступе к файлам через WebDAV. Проблема заключается в том, что клиенты WebDAV, которые подключаются к серверу "обрывают" отображение папок и файлов, как только встречают названия на русском.
Во всех клиентах была включена кодировка UTF-8 принудительно. Эти же самые клиенты при подключении к серверу на основе apache.mod_dav всё отображают правильно.

Что можно сделать с этой проблемой? Что настроить?

Список клиентов и как они отрабатывали запросы к ngnix:
1. Обычные (любые) вебраузеры - отлично. Всё показывали и скачивали.
2. NetDrive - не показывает русские буквы, но отлично показывает английские.
3. WebDrive - хорошо показывает все буквы.
4. TotalCmd - хорошо показывает все буквы, но не работает с каталогами с пробелами.
5. freebsd. dvfs - не показывает русские буквы (на apache показывает).

Собственно конфигурация nginx ниже (привожу почти без вырезаний на всякий случай. Сам WebDAV в самом низу):

#-------------------------------------------------------------------------------
# Конфигурация front-end web-сервера (далее "Сервер"), обслуживающего запросы
# виртуальных серверов:
#-------------------------------------------------------------------------------

# Имя пользователя и группы, с которыми запускается сервер.
user www www;

# Количество процессов, обслуживающих запросы к серверу.
# auto - количество запросов определяется с привязкой к количеству процессоров.
worker_processes auto;

# Определяет контекст для директив, связанных с обработкой запросов.
events {
worker_connections 1024;
}

# Определяет контекст для директив http-сервера.
http {
# Общий формат сообщений в журнал.
log_format default '[$time_local] $remote_addr $remote_user "$request" $status $bytes_sent';
# Системный формат сообщений в журнал.
log_format system '[$time_local] $remote_addr $remote_user "$http_user_agent" "$http_referer"';

# Журнал всех, обрабатываемых сервером, сообщений.
access_log /var/log/nginx/common-access.log default buffer=32k flush=1m;
# Вспомогательный журнал системных сообщений.
access_log /var/log/nginx/common-system.log system buffer=32k flush=1m;
# Журнал всех ошибок сервера.
error_log /var/log/nginx/common-error.log;

# Подключение описаний известных серверу mime-типов.
include /usr/local/etc/nginx/mime.types;
# mime-тип по умолчанию для потоков, не объявивших свой тип самостоятельно.
default_type application/octet-stream;
# Кодировка сервера по умолчанию.
charset utf-8;

# Размер тела сообдения от клиента.
client_max_body_size 10M;
client_body_temp_path /db/tmp/nginx;

# back-end сервера.

upstream svn.db { server 127.0.0.1:49408; }
upstream trac.db { server 127.0.0.1:4096; }
upstream trac.home { server 127.0.0.1:4097; }

upstream svn.storage { server 127.0.0.1:49409; }
upstream trac.storage.general { server 127.0.0.1:49407; }
upstream trac.storage.espd { server 127.0.0.1:49406; }
upstream trac.storage.eskd { server 127.0.0.1:49405; }
upstream trac.storage.sgpms { server 127.0.0.1:49404; }
upstream trac.storage.adaptation { server 127.0.0.1:49403; }
upstream trac.storage.station { server 127.0.0.1:49402; }

# Конфигурация виртуального сервера https://db.npcprom.ru.
server {
# Корневой каталог файлов сервера.
root /db/www/nginx;

# Имя виртуального сервера.
server_name db db.example.com;

# Параметры ssl-шифрования.
include /db/conf/nginx-ssl.conf;

# Параметры авторизации.
include /db/conf/nginx-auth.conf;

# Время ожидания ответа от tracd.
proxy_read_timeout 240;

# Обработка пути /trac или /home
location / {

# Обработка статических файлов Trac.
include /db/conf/nginx-trac-htdocs.conf;

# Обработка пути /trac
location /trac {
# Журнал доступа к Trac.
access_log /var/log/nginx/db-trac.log default buffer=32k flush=5;

# Адрес back-end сервера Trac.
proxy_pass http://trac.db;
proxy_pass_header Authorization;
}

# Обработка пути /svn
location /svn {
# Журнал доступа к Subversion.
access_log /var/log/nginx/db-svn.log default buffer=32k flush=5;

# Адрес back-end сервера Subversion.
proxy_pass http://svn.db;

# Параметры back-end сервера Subversion.
include /db/conf/nginx-subversion.conf;
}


# ---- Вот, собственно location с WebDAV

# Обработка пути /files
location /files {
# Журнал доступа к файлам.
access_log /var/log/nginx/db-files.log default buffer=32k flush=5;

# Корневая директория для файлов.
root /db/www/db/;

autoindex on;

client_max_body_size 16G;

dav_methods PUT DELETE MKCOL COPY MOVE;
dav_ext_methods PROPFIND OPTIONS;

create_full_put_path on;

dav_access group:rw all:rw;

limit_except GET {
allow all;
# deny all;
}
}
}
}
}

Rewrite Help (no replies)

$
0
0
Hi,

I am what Nginx and regex concerns still very inexperienced.

Hopefully you can help me.

Nginx is used as a reverse proxy.

The following should be implemented.

Current Url
-> Http://www.example.de/web/user1
should look like this:
-> Http://www.example.de

and
-> Http://www.example.de/web/oranisation
should look like this:
-> Http://www.example.de/oranisation.

Greetings
OSC

Nginx 1.4.4-4 / limit_conn / limit rate (no replies)

$
0
0
Dear honorable members,

I switched recently from Apache / Debian to Nginx / Debian and
i'm struggling a bit right now. I hope to find some help in this forum.

System info:
Nginx-Full 1.4.4-4 / Debian Jessie

Goal:
Limit the connections per IP to 1 with a limited bandwith (20 Megabit/s) for every connection.

Done so far:
nginx.conf:
limit_conn_zone $binary_remote_addr zone=addr:10m;

in the location block:
limit_conn addr 1;
limit_rate 2621440;

I see a lot of entries in the error.log looking like this:

limiting connections by zone addr ...

I assume, that the limit_conn is working, but people are still downloading with 100 MBit/s or more. Im stuck and would really appreciate some advice.

Thank you in advance.
Viewing all 2931 articles
Browse latest View live


Latest Images