Jump to content

nginx rewrite problem


Recommended Posts

Posted

Hello,

Recently I have installed nginx and everything seems to work fine except rewrite rulles. Currently my config looks like :



location / {

	 root /home/zzz/www;

	 index index.html index.php;

	 try_files $uri $uri/ /index.php?q=$uri&$args;

}


location ~ .php$ {

	 root /home/zzz/www;

	 set $script $uri;

	 set $path_info "";

	 if ($uri ~ "^(.+.php)(/.+)") {

		 set $script $1;

		 set $path_info $2;

	 }

	 include /etc/nginx/fastcgi_params;

	 fastcgi_pass 127.0.0.1:9000;

	 fastcgi_index index.php;

	 fastcgi_param SCRIPT_FILENAME $document_root$script;

	 fastcgi_param SCRIPT_NAME $script;

	 fastcgi_param PATH_INFO $path_info;

	 }



Forums, topics, posts and others rewrites are working the same as apache but announcements wchich has statement like
http://www.myforum.c...ncement-1-data/

are getting error.

Can anyone support me in writing correct rulles to get forum announcements work ?

Best Regards,

Posted

Hi,

Here is a working example:


file: /etc/nginx/sites-available/example.com


server {

	 listen 80;

	 server_name www.example.com;

	 root /srv/www/example.com/public;

	 index index.php index.html;

	 access_log /var/log/nginx/example-access.log main;

	 error_log /var/log/nginx/example-error.log;

	 # Main location

	 location / {

		 try_files $uri $uri/ /index.php;

	 }

	 ## Static files location

	 location ~* ^.+.(css|js|jpg|jpeg|gif|png|ico)$ {

		 access_log off;

		 log_not_found off;

		 expires 30d;

		 add_header Pragma "public";

	 }

	 ## PHP

	 location ~ \.php$ {

		 include php5_params;

	 }

}


file: /etc/nginx/php5_params


# PHP

try_files $uri = 404;

fastcgi_split_path_info ^(.+\.php)(/.+)$;

fastcgi_index index.php;

include fastcgi_params;

fastcgi_param PATH_INFO	 $fastcgi_path_info;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_pass php5-fpm;


file: /etc/nginx/nginx.conf


your stuff

......

upstream php5-fpm {

server unix:/var/run/php5-fpm.sock;

}

Posted

thank you !




Hi,

Here a more secure config:



server {

    listen 80;

    server_name www.example.com;

    root /srv/www/example.com/public;

    index index.php index.html;

    access_log /var/log/nginx/example-access.log main;

    error_log /var/log/nginx/example-error.log;


    ## Deny .htaccess

    location ~ /. {

        access_log off;

        log_not_found off;

        deny all;

    }


    ## Disable php file execution

    location ~* ^/(?:cache|hooks|public/style_css|public/style_images|uploads)/.*.(?:pl|php[345]*)$ {

        access_log off;

        log_not_found off;

        return 404; # or 403

    }


    # Main location

    location / {

        try_files $uri $uri/ /index.php;

    }


    ## Static files location

    location ~* ^.+.(css|js|jpg|jpeg|gif|png|ico)$ {

        access_log off;

        log_not_found off;

        expires 30d;

        add_header Pragma "public";

    }


    ## PHP

    location ~ .php$ {

        include php5_params;

    }

}


Posted

Just to note... you don't actually need a rewrite per se...

IPB wants everything to be redirected to the index.php. So, you can just write...

fastcgi_param SCRIPT_NAME index.php;
instead of leaving a variable.

So, you'll need one for forums.. and another for your IP.C if existing so they can direct to the forum's index and ipc's index.

And then file all the non-php stuff, namely images, ico, css & js files to serve directly as nginx.

This way, you don't do any rewrites, virtually no re-trying of useless files.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...