rewrite rules with nginx

tofane69

New member
Joined
Jun 7, 2014
Messages
3
hi

i have directadmin + apache and now my server support installed nginx for me so now i have direct admin + nginx (standalone)
the script that i use also give me rewrite rules to add to nginx but i face some problem with this

they said that i should edit
Code:
/etc/nginx/sites-available/default
but there is no such file or directory with that path!!!
also in the content the code it needs my web root path
Code:
/usr/share/nginx/www
but i don't have such this directory in my server too
i use centos 6.5
 
now what i need is to add
Code:
/var/run/php5-fpm.sock
but it is not available in my server! i just have mydomain.com.sock!
what should i do to have this file?
 
what to do with this error when i add the rewrite codes
Code:
nginx: [emerg] "location" directive is not allowed here in /usr/local/directadmin/data/users/uploadtera/nginx.conf:43
here is the all code that support of my script give me to add,would you please edit this for me?

PHP:
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;
                }
        }
}
 
I'm suffering about the same problem with the nginx vs apache mod_rewrite to get clean URL's (it's for a Joomla driven site).

Looking at the instructions at http://docs.joomla.org/Enabling_Search_Engine_Friendly_(SEF)_URLs#Nginx I added next lines to my /etc/nginx/nginx.conf but this results in a 500 Internal Server Error

location / {
........
........
try_files $uri $uri/ /index.php?q=$request_uri;
........
}
 
I guess you can not specify one location several times. So you need to modify/customize templates and add there a set of custom variables, so you could use them in Directadmin here: Admin Panel -> Admin Settings -> Customize Httpd Configurations

Probably somebody on these forums can do that for you for free. But if I do it for you, then it will cost you some money. Currently I don't use standalone NGINX with WP, Joomla, etc for my own. So I don't have a ready made solution. I'll need spent time to make the things to work for you. Please PM me for details if you are interested.
 
nginx

The only code you have to add is:

Code:
location / {
    try_files $uri $uri/ /index.php?$args;
}
 
Ps, i forgot to mention, but please never and really never use if in Nginx config!!

For more info read this: http://wiki.nginx.org/IfIsEvil

Thanks Hardie for your kind help. It seems to work fluidly.
I think it's harder to get this to work when you have a dedicated nginx system, rather than (in my case) nginx as proxy.

I even doubt if I need to add this line to the system, as Apache is still working the system (like Joomla), and to get clean url's working I still need .htaccess, but that's fine by me, as this makes life simpler for future customers as they can keep on doing what they are used to be doing, and that's working in plain apache systems. So it's Business as usual :)
 
Back
Top