Jump to content
php.lv forumi

CI + Nginx + Rewrite


Recommended Posts

Sveiki,

 

lietoju subdomain.domain.com ar CI (Codeigniter).

 

Apache gadijumā, lai CI veiksmīgi darbotos, neteikšu ka vienmēr, nepieciešams htaccess.

 

Lūk ejošs variants [.htacess]

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /
   RewriteCond %{REQUEST_URI} ^scripts.*
   RewriteRule ^(.*)$ /index.php/$1 [L]
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
   ErrorDocument 404 /index.php
</IfModule>

 

Bet pārejot uz nginx, sastopos ar zināmām grutībām pārfrāzēt šo rewrite uz nginx saprotamu vidi.

 

1) Vajadzētu sarpast, kurā failā kas tiek rakstīts - vai ir kāds kopīgais fails kurā tiek rakstīts tas, ko agrāk apacī rakstija atseviški htaccess failos ?

2) Kā šo apache htaccess failu iedarbināt uz nginx ?

Link to comment
Share on other sites

1) Ja veru adresi www.xxx.lv/ man palaizas kautkads "download" file, bet tur ir jabut baltai lapai

2) Ja veru adresi www.xxx.lv/test1/test2/test3 paradas redirekts www.xxx.lv/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php//test1/test2/test3

 

location / {
      proxy_pass http://xxx.xxx.xxx.xxx:8080;
                   proxy_redirect http://xxx.lv:8080/ /;
                     proxy_set_header Host $host;
                      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                     proxy_set_header X-Real-IP $remote_addr;


if (-f $request_filename) {
     expires 30d;
     break;
   }
if (!-e $request_filename) {
     rewrite . /index.php last;
   }

}



########################## ( Fast CGI ) ###########################################################################
#location ~ \.php$ {                                                                                            ###
#       fastcgi_pass 127.0.0.1:9000;                                                                            ###
#       fastcgi_index index.php;                                                                                ###
#       include /etc/nginx/fastcgi.conf;                                                                        ###
#       fastcgi_param SCRIPT_FILENAME /var/xxxx.lv/index.php;              ###
#}                                                                                                              ###
###################################################################################################################

Link to comment
Share on other sites

Man šķiet, ka "RewriteRule ^(.*)$ index.php/$1 [L]" un "rewrite . /index.php last;" nebūs viens un tas pats. Manā dotajā piemērā jau arī nav notestēts, bet nu uz to pusi jau ir. Beigās vēl neaizmirsti par scripts rulli, bet vispirms, protams, jāpiedabūt, lai pārējais darbotos.

 

if (!-e $request_filename) {
 rewrite ^(.*)$  /index.php/$1 last;
}

 

Tas gan jātastē, jo tam nginx visādi triki mēdz izlīst atkarībā no "root"

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...