Jump to content

Allow url rewrite nginx


LightScribe

Recommended Posts

Hello!

Im using VestaCP with nginx+php-fpm. I have enabled Rewrite URLs in admin panel (Search engine optimization). Problem is that Im using nginx and nginx doesnt using htaccess file which I needed for Rewrite URLs.

I put this in my nginx config file, but when I visit my forum it just start downloading page.

location /forums/ {
  if (!-e $request_filename){
    rewrite \.(js|css|jpeg|jpg|gif|png|ico|map)(\?|$) /forums/forums/404error.php break;
  }
  if (!-e $request_filename){
    rewrite ^/forums/(.*)$ /forums/forums/index.php break;
  }
}

What I did wrong?

Link to comment
Share on other sites

You can use something like this :

server {
    listen 80; 
	
    server_name example.com;
	
    access_log logs/example.com_access.log;
    error_log logs/example.com_error.log;
    root /home/forums;
    index  index.php;
	
    location / {
	try_files  $uri $uri/ /index.php;
        } 
		
       location ~ \.php$ {
            try_files $uri $uri/ /index.php;
            fastcgi_pass   unix:/run/php/php7.0-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
 		   
}

Of course you will have to change it to suit your needs and may be add more security/performance related settings .

Your issue  "nginx start downloading your page (php file)" is due to  php location not set or wrong configuration for :

fastcgi_pass unix:/run/php/php7.0-fpm.sock;

 

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...