nginx config

coffee

New Member
Jul 23, 2014
83
0
0
I've setup an nginx file server recently. Went to add it and ran a test in the file server tab. It's asking for .htaccess/mod_rewrite support. I've added the rules to the nginx.config which should be alright, but it still errors out there and won't take uploads.

Code:
user  nginx;

# The number of worker processes is changed automatically by CustomBuild, according to the number of CPU cores, if it's set to "1"
worker_processes  20;
pid /var/run/nginx.pid;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

events {
    include /etc/nginx/nginx-events.conf;
}

http {
    include       /etc/nginx/mime.types;

    # For user configurations not maintained by DirectAdmin. Empty by default.
    include /etc/nginx/nginx-includes.conf;
    
    # Supplemental configuration
    include /etc/nginx/nginx-defaults.conf;
    include /etc/nginx/nginx-gzip.conf;
    include /etc/nginx/directadmin-ips.conf;
    include /etc/nginx/directadmin-settings.conf;
    include /etc/nginx/nginx-vhosts.conf;
    include /etc/nginx/directadmin-vhosts.conf;

server {
	listen   80; ## listen for ipv4; this line is default and implied

	root /usr/share/nginx/www;
	index index.php;
	client_max_body_size 5G;

	# Make site accessible from http://localhost/
	server_name localhost;

	# pass the PHP scripts to FastCGI server listening
	location ~ \.php$ {
		# With php5-fpm:
		fastcgi_pass unix:/var/run/php5-fpm.sock;
		fastcgi_index index.php;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include fastcgi_params;
	}

	location / {
		if (!-f $request_filename){
				set $rule_0 1$rule_0;
		}
		if (!-d $request_filename){
				set $rule_0 2$rule_0;
		}
		if ($rule_0 = "21"){
				rewrite ^/(.*) /index.php?_page_url=$1 last;
		}
	}
}
}
I'm not too experienced with nginx myself, so I figured I'd look for tips here. Also, this was a DA control panel server. Possibly help some others out with the new rules.

Aside form this, everything else seems to load alright and it connects to the database just fine.
 

lajusangat

New Member
YetiShare User
Oct 1, 2012
20
0
1
Hi Coffee,

Try this,
Code:
vi /usr/local/etc/nginx/vhosts/heavyloadeddomain.conf
Code:
# less /usr/local/etc/nginx/vhosts/heavyloadeddomain.conf
#
 server {
        listen     _SERVERIP_:81;
        server_name  _HEAVYLOADEDDOMAIN_ www._HEAVYLOADEDDOMAIN_;
        charset off;
        access_log  /var/log/nginx/_HEAVYLOADEDDOMAIN_.access.log  main;

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

        # proxy the PHP scripts to Apache
        location / {
                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_pass              http://217.20.175.140;
                proxy_buffering         off;
                error_page              502 503 /usr/local/www/nginx-dist/50x.html;
				if (!-f $request_filename){
					set $rule_0 1$rule_0;
				}
				if (!-d $request_filename){
					set $rule_0 2$rule_0;
				}
				if ($rule_0 = "21"){
					rewrite ^/(.*) /index.php?_page_url=$1 last;
				}
        }

        #static files
        location ~* ^.+.(nrg|htm|html|jpg|jpeg|gif|png|ico|css|zip|7z|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|avi|mp3|mp4|mpg|iso|djvu|dmg|flac|r70|mdf|chm|sisx|sis|flv|thm|bin)$ {

           root /home/_USER_/domains/_HEAVYLOADEDDOMAIN_/public_html/;
        }
    }
 

coffee

New Member
Jul 23, 2014
83
0
0
hmmm so had the wrong rules. They were changed after the first release of v4

Code:
user  nginx;
 
# The number of worker processes is changed automatically by CustomBuild, according to the number of CPU cores, if it's set to "1"
worker_processes  20;
pid /var/run/nginx.pid;
 
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
events {
    include /etc/nginx/nginx-events.conf;
}
 
http {
   
server {
    listen       80;
    server_name  ""; # set to all
    root html;
    index index.php;
    client_max_body_size 5G;
 
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
        if (!-e $request_filename) { rewrite ^/(.*) /index.php?_page_url=$1 last; }
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
 
    location / {
                if (!-e $request_filename) {
                rewrite ^/(.*) /index.php?_page_url=$1 last;
                }
    }
 
    location /files/ {
        internal;
    }
 
    # these locations would be hidden by .htaccess normally
    location /core/logs/ {
        deny all;
    }
}
}
Which seems to cause a redirection error:

2014/10/31 10:35:46 [error] 5773#0: *1 rewrite or internal redirection cycle while processing "/index.php", client: IP here, server: , request: "GET /favicon.ico HTTP/1.1", host: "domainhere.com"


Anyone with ideas on this?
 

admin4170

Member
Aug 8, 2014
30
0
6
coffee said:
hmmm so had the wrong rules. They were changed after the first release of v4

Code:
user  nginx;
 
# The number of worker processes is changed automatically by CustomBuild, according to the number of CPU cores, if it's set to "1"
worker_processes  20;
pid /var/run/nginx.pid;
 
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
events {
    include /etc/nginx/nginx-events.conf;
}
 
http {
   
server {
    listen       80;
    server_name  ""; # set to all
    root html;
    index index.php;
    client_max_body_size 5G;
 
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    location ~ \.php$ {
        if (!-e $request_filename) { rewrite ^/(.*) /index.php?_page_url=$1 last; }
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
 
    location / {
                if (!-e $request_filename) {
                rewrite ^/(.*) /index.php?_page_url=$1 last;
                }
    }
 
    location /files/ {
        internal;
    }
 
    # these locations would be hidden by .htaccess normally
    location /core/logs/ {
        deny all;
    }
}
}
Which seems to cause a redirection error:

2014/10/31 10:35:46 [error] 5773#0: *1 rewrite or internal redirection cycle while processing "/index.php", client: IP here, server: , request: "GET /favicon.ico HTTP/1.1", host: "domainhere.com"


Anyone with ideas on this?
Hi, I use Direct Admin and this is my problem. it cannot load without /index.php
http://forum.mfscripts.com/viewtopic.php?f=20&t=1989

Please help