Rewrite on Nginx (version 3.5.x)

Status
Not open for further replies.

trasserx1958

New Member
YetiShare User
Nov 24, 2012
5
0
0
#1
Hello,
i am using this file hosting script with Nginx without any problems,
my opinion is that Apache should retire years ago, it fills up your ram and kill the servers processor if you have any good traffic to your site,
that is why im using Nginx, Apache its loading new thread (2-3mb ram) per visitor, that it why your ram fills up and why your processor is on high load
with Nginx on the other hand it's only use one thread to handle all request and i can't barely see any server load or memory use at all with tons of visitor, Netflix and Facebook and many more sites its using Nginx, that is why i love Nginx.

But Here's is the rewrite:

server {
listen 80; # your server's public IP address
server_name site.com; # your domain name
root /usr/share/nginx/www/public_html/site.com/public/; # absolute path to your installation

index index.php index.html index.htm;
client_max_body_size 5G;

location / {
try_files $uri $uri/ /index.php?page_request=$uri;

if ($uri ~ "^(.+)~s$"){
set $rule_0 1$rule_0;
}
if ($rule_0 = "1"){
rewrite ^/(.*) /stats.php?u=$1 last;
}
if ($uri ~ "^(.+)~d$"){
set $rule_0 1$rule_0;
}
if ($rule_0 = "1"){
rewrite ^/(.*) /delete_file.php?u=$1 last;
}
if ($uri ~ "^(.+)~i$"){
set $rule_0 1$rule_0;
}
if ($rule_0 = "1"){
rewrite ^/(.*) /share_file.php?u=$1 last;
}
if ($uri ~ "^(.+)~f$"){
set $rule_0 1$rule_0;
}
if ($rule_0 = "1"){
rewrite ^/(.*) /view_folder.php?f=$1 last;
}
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 ^/(.*) /file_download.php?u=$1 last;
}

}

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}

Hope it helps! :D
 

adam

Administrator
Staff member
Dec 5, 2009
1,635
17
38
mfscripts.com
WEBSITE
https://yetishare.com
LOCATION
UK
#2
Re: Rewrite on Nginx

How do you set this up on Nginx, do you just add the text to a .htaccess file like in Apache?

Thanks for sharing, this will be really useful for a lot of other users. :)
 

adam

Administrator
Staff member
Dec 5, 2009
1,635
17
38
mfscripts.com
WEBSITE
https://yetishare.com
LOCATION
UK
#3
Re: Rewrite on Nginx

Dont worry, I've just found this info:

"Rewrites can go into the server{} section of your nginx configuration."
 

leszekstaron2224

New Member
YetiShare User
Feb 18, 2013
1
0
0
#5
Re: Rewrite on Nginx

My version:
Code:
 rewrite ^(.*).html$ $1.php break;
 
 if ($request_uri ~ "^(.+)\~s$")
 {
        rewrite ^/(.*) /stats.php?u=$1
        break;
 }
 if ($request_uri ~ "^(.+)\~d\?(.+)$")
 {
        rewrite ^/(.*) /delete_file.php?u=$1
        break;
 }
 if ($request_uri ~ "^(.+)\~i$")
 {
        rewrite ^/(.*) /share_file.php?u=$1
        break;
 }
 if ($request_uri ~ "^(.+)\~f$")
 {
        rewrite ^/(.*) /view_folder.php?u=$1
        break;
 }
 if (-f $request_filename) { break;}
 if (-d $request_filename) { break;}
 
 rewrite ^/(.+)$ /file_download.php?u=$1;
 

shopping1782

New Member
YetiShare User
Wurlie User
Reservo User
Sep 12, 2012
97
0
0
#6
Re: Rewrite on Nginx

Thanks guys!
I will probably try it in near future.
I was wondering - did nginx enabled file support for files over 2GB? Or did you guys resolved this some other way?
 

shopping1782

New Member
YetiShare User
Wurlie User
Reservo User
Sep 12, 2012
97
0
0
#8
Re: Rewrite on Nginx

uploadchest said:
again, you change it in your php.ini.
so when nginx + php.ini is updated it's ready to go? No need to compile the x64 version of PHP?
 

adam

Administrator
Staff member
Dec 5, 2009
1,635
17
38
mfscripts.com
WEBSITE
https://yetishare.com
LOCATION
UK
#9
Re: Rewrite on Nginx

shopping1782 said:
uploadchest said:
again, you change it in your php.ini.
so when nginx + php.ini is updated it's ready to go? No need to compile the x64 version of PHP?
The limitation is a PHP one so I can't see changing the web server to nginx will help.
 
Apr 30, 2012
96
0
0
#11
Re: Rewrite on Nginx

Hi,

i have upgrade to the my server to NGIX but the stats rule doesnt work. Any clue what happend ?

rewrite ^(.*).html$ $1.php break;

if ($request_uri ~ "^(.+)\~s$")
{
rewrite ^/(.*) /stats.php?u=$1
break;
}
if ($request_uri ~ "^(.+)\~d\?(.+)$")
{
rewrite ^/(.*) /delete_file.php?u=$1
break;
}
if ($request_uri ~ "^(.+)\~i$")
{
rewrite ^/(.*) /share_file.php?u=$1
break;
}
if ($request_uri ~ "^(.+)\~f$")
{
rewrite ^/(.*) /view_folder.php?u=$1
break;
}
if (-f $request_filename) { break;}
if (-d $request_filename) { break;}

rewrite ^/(.+)$ /file_download.php?u=$1;

regards

Istvan
 

halalrizik2841

New Member
YetiShare User
Aug 5, 2013
40
0
0
#14
Re: Rewrite on Nginx

This is bit confusing, when i open the php.ini file to add the above code, i don't know where to add this code. Please help.

And am i suppose to add the code by trasserx1958 or by leszekstaron2224

Please help.

Thanks.
 

adam

Administrator
Staff member
Dec 5, 2009
1,635
17
38
mfscripts.com
WEBSITE
https://yetishare.com
LOCATION
UK
#16
Re: Rewrite on Nginx

The rules may vary slightly depending on nginx version. We use the following:

In:

Code:
/etc/nginx/sites-available/default
Change to:

Code:
server {
        listen   80; # port number

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

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

	# treat all .php files as php
        location ~ \.php$ {
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }

	# rewrite all .html to .php
        location ~ \.html$ {
                rewrite ^/(.*).html /$1.php last;
        }

	# other rewrite rules
        location / {
                try_files $uri $uri/ /index.php?page_request=$uri;

                if ($uri ~ "^(.+)~s$"){
                        set $rule_0 1$rule_0;
                }
                if ($rule_0 = "1"){
                        rewrite ^/(.*) /stats.php?u=$1 last;
                }
                if ($uri ~ "^(.+)~d$"){
                        set $rule_0 1$rule_0;
                }
                if ($rule_0 = "1"){
                        rewrite ^/(.*) /delete_file.php?u=$1 last;
                }
                if ($uri ~ "^(.+)~i$"){
                        set $rule_0 1$rule_0;
                }
                if ($rule_0 = "1"){
                        rewrite ^/(.*) /share_file.php?u=$1 last;
                }
                if ($uri ~ "^(.+)~f$"){
                        set $rule_0 1$rule_0;
                }
                if ($rule_0 = "1"){
                        rewrite ^/(.*) /view_folder.php?f=$1 last;
                }
                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 ^/(.*) /file_download.php?u=$1 last;
                }
        }
}
You may need to change the paths depending on how you installed it.

This is based on the following resources for installing nginx:

https://www.digitalocean.com/community/articles/how-to-install-linux-nginx-mysql-php-lemp-stack-on-debian-7
https://www.digitalocean.com/community/articles/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-6
 

ysmods

New Member
Jan 29, 2013
860
0
0
UK
www.ysmods.com
WEBSITE
https://www.ysmods.com
LOCATION
UK
#18
Re: Rewrite on Nginx

Login to ssh as root and run these commands to install nginx

Code:
cd /usr/local/src
wget http://nginxcp.com/latest/nginxadmin.tar
tar xf nginxadmin.tar
cd publicnginx
./nginxinstaller install
Uninstall Instructions:

Code:
cd /usr/local/src
wget http://nginxcp.com/latest/nginxadmin.tar
tar xf nginxadmin.tar
cd publicnginx
./nginxinstaller uninstall
http://lmgtfy.com/?q=install+nginx+on+cpanel
 

halalrizik2841

New Member
YetiShare User
Aug 5, 2013
40
0
0
#19
Re: Rewrite on Nginx

I tried that plugin already, but the problem is that it does not show this path : root /usr/share/nginx/www/public_html

How do i get to this path when there is nothing Nginx in /usr/share/ directory.

Thanks.
 

zigma4000

Member
YetiShare User
Wurlie User
Jun 9, 2013
39
0
6
UAE
www.uploadman.com
WEBSITE
http://www.uploadman.com
LOCATION
UAE
#20
Re: Rewrite on Nginx

Well ,

Can you put all your settings, please ?

I install and configed Nginx , loading pages are much faster.

but each download with IDM and 8 concurrent connections take 500MB RAM and 99% load on 4 cores of CPU !

I didn't have this problem with apache_nginx reverse proxy , but with Nginx alone its too muxh load !
 
Status
Not open for further replies.