we have an older version of Magento (1.4) running on an nginx server. We have a few temporary redirects (302's) on the site that need to be converted to permanent 301 redirects.. There is no way to do this in 1.4 by means of the Administraton Panel :(
Can anyone provide me with the nginx configuration directives to do this?
Here is my config file for the domain:
rewrite ^/minify/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last;
rewrite ^/skin/m/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ #handler; ## If missing pass the URI to Magento's front handler
expires 30d; ## Assume all files are cachable
}
location /app/ { deny all; }
location /includes/ { deny all; }
location /lib/ { deny all; }
location /media/downloadable/ { deny all; }
location /pkginfo/ { deny all; }
location /report/config.xml { deny all; }
location /var/ { deny all; }
location /lib/minify/ {
allow all;
}
location /var/export/ { ## Allow admins only to view export folder
auth_basic "Restricted"; ## Message shown in login window
auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
autoindex on;
}
location /. { ## Disable .htaccess and other hidden files
return 404;
}
location #handler { ## Magento uses a common front handler
rewrite / /index.php;
}
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}
location ~* ^(.+\.php)(.*) {
if (!-e $request_filename) { rewrite ^(.*)$ /index.php break; }
## Catch 404s that try_files miss
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param HTTPS $fastcgi_https;
#fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
#fastcgi_param MAGE_RUN_TYPE store;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/luxuryleathergoods.com/public_html$fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include fastcgi_params;
}
}
For each redirect, you can add the following line to your nginx configuration, inside of the location / block (first):
rewrite /old/url.html /new/url.html
Related
In root directory I have Drupal. In sub directory I have Magento. Most probably drupal rewrites overlap magento rewrites.
Magento homepage opening successfully without any nginx config, but links don't work.
I'm not sure, but I think to resolve the problem I need exclude magento directory from drupal routing.
And another thing is, I'm not sure if I have proper magento config.
root config:
server {
listen 80;
root /var/www/domain;
index index.php index.html index.htm;
server_name domain.com;
location /fe {
proxy_pass http://domain.com:1234/visualization;
}
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/domain;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9$
location ~ \.php$ {
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
magento config
server {
listen 80;
## SSL directives might go here
server_name domain.com; ## Domain is here twice so server_name_in_redirect will favour the www
root /var/www/domain/magento;
location / {
index index.html index.php; ## Allow a static html file to be shown first
try_files $uri $uri/ #handler; ## If missing pass the URI to Magento's front handler
# try_files $uri $uri/ /index.php?q=$uri&$args;
expires 30d; ## Assume all files are cachable
}
## These locations would be hidden by .htaccess normally
location ^~ /app/ { deny all; }
location ^~ /includes/ { deny all; }
location ^~ /lib/ { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/ { deny all; }
location ^~ /report/config.xml { deny all; }
location ^~ /var/ { deny all; }
## location ~ /\.ht { deny all; }
location /var/export/ { ## Allow admins only to view export folder
auth_basic "Restricted"; ## Message shown in login window
auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
autoindex on;
}
## location /.
location ~ /\.ht { ## Disable .htaccess and other hidden files
return 404;
}
location /api {
rewrite ^/api/rest /api.php?type=rest last;
}
location #handler { ## Magento uses a common front handler
rewrite / /index.php;
}
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}
location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
expires off; ## Do not cache dynamic content
fastcgi_pass unix:/var/run/php5-fpm.sock;
## fastcgi_pass 127.0.0.1:8079;
##fastcgi_read_timeout 10800s;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
Best way is use some subdomain for magento, like https://shop.yourdomain.com. But if you want to keep it as http://yourdomain.com/magento you need to remove separate nginx config file for Magento and add /magento/ location to root config. I mean:
location /magento/ {
root /var/www/domain/magento; #main thing
index index.html index.php;
try_files $uri $uri/ #handler;
expires 30d;
}
location ^~ /magento/app/ { deny all; }
location ^~ /magento/includes/ { deny all; }
location ^~ /magento/lib/ { deny all; }
location ^~ /magento/media/downloadable/ { deny all; }
location ^~ /magento/pkginfo/ { deny all; }
location ^~ /magento/report/config.xml { deny all; }
location ^~ /magento/var/ { deny all; }
location ~ /magento/\.ht { deny all; }
etc.
Then you need to check Magento Secure/Unsecure URL. It should be http://yourdomain.com/magento/ You can change it via admin panel or directly in database (core_config_data table). In the end clear the cache and restart Nginx.
I tried to install Magento Community Edition to my VPS(on Linode) with Nginx and php-fpm but I couldn't. I downloaded Magento 1.8.1.0 to my server. I created nginx configurations like Magento Wiki. But when I request my domain, it redirects to '/index.php/install/' path by 302 header and browser gives infinite loop error.
Can you suggest a workaround about that?
EDIT: My nginx configuration file (I replaced real domain name as mydomain)
server {
server_name mydomain.com www.mydomain.com;
root "/home/mydomain/public_html";
index index.php;
client_max_body_size 10m;
access_log /home/mydomain/_logs/access.log;
error_log /home/mydomain/_logs/error.log;
if ($http_user_agent ~* (Baiduspider|webalta|nikto|wkito|pikto|scan|acunetix|morfeus|webcollage|youdao) ) {
return 401;
}
if ($http_user_agent ~* (HTTrack|clshttp|archiver|loader|email|harvest|extract|grab|miner) ) {
return 401;
}
location / {
index index.html index.php; ## Allow a static html file to be shown first
try_files $uri $uri/ #handler; ## If missing pass the URI to Magento's front handler
expires 30d; ## Assume all files are cachable
}
## These locations would be hidden by .htaccess normally
location ^~ /app/ { deny all; }
location ^~ /includes/ { deny all; }
location ^~ /lib/ { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/ { deny all; }
location ^~ /report/config.xml { deny all; }
location ^~ /var/ { deny all; }
location /var/export/ { ## Allow admins only to view export folder
auth_basic "Restricted"; ## Message shown in login window
auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
autoindex on;
}
location /. { ## Disable .htaccess and other hidden files
return 404;
}
location #handler { ## Magento uses a common front handler
rewrite / /index.php;
}
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}
location ~ "^(.+\.php)($|/)" {
if (!-e $request_filename) { rewrite / /index.php last; }
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default;
fastcgi_param MAGE_RUN_TYPE store;
fastcgi_param HTTPS $https;
fastcgi_pass unix:/var/run/mydomain_fpm.sock;
include fastcgi_params;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
access_log off;
}
location ~* \.(html|htm)$ {
expires 30m;
}
location ~* /\.(ht|git|svn) {
deny all;
}
}
Basicly, if you do not have crated database yet, it will be problem in Nginx and virtual hosting configuration.
Possible fault will be in memory of your browser. Try to clean it up, or use anonymous regime.
Try to remove magento files and create a simple index.php file with "hello" text inside. If it works try to copy Magento files again to this folder and run installation.
Have on mind, you MUST create a empty database with user having all rights to this database.
Second issue can be in fault installation, (Your magento is installed yet, and you trying to connect installer again, but this will redirect). In this case is something wrong in installation, remove tables from database and run installation again.
My file looks like this:
server {
listen 80 default;
access_log /var/log/nginx/test.ssl.access.log;
error_log /var/log/nginx/test.ssl.error.log;
ssl off;
root /var/www/shop;
server_name sales.test.net.au;
location / {
index index.html index.php;
try_files $uri $uri/ #handler;
expires 30d;
}
location ^~ /app/ { deny all; }
location ^~ /includes/ { deny all; }
location ^~ /lib/ { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/ { deny all; }
location ^~ /report/config.xml { deny all; }
location ^~ /var/ { deny all; }
location /var/export/ { ## Allow admins only to view export folder
auth_basic "Restricted"; ## Message shown in login window
auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
autoindex on;
}
location /. { ## Disable .htaccess and other hidden files
return 404;
}
location #handler { ## Magento uses a common front handler
rewrite / /index.php;
}
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}
location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; }
expires off; ## Do not cache dynamic content
fastcgi_pass 127.0.0.1:9000;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default;
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
}
server {
listen 443 default;
ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
access_log /var/log/nginx/test.ssl.access.log;
error_log /var/log/nginx/test.ssl.error.log;
server_name sales.test.net.au;
root /var/www/shop;
location / {
index index.html index.php;
try_files $uri $uri/ #handler;
expires 30d;
}
location ^~ /app/ { deny all; }
location ^~ /includes/ { deny all; }
location ^~ /lib/ { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/ { deny all; }
location ^~ /report/config.xml { deny all; }
location ^~ /var/ { deny all; }
location /var/export/ { ## Allow admins only to view export folder
auth_basic "Restricted"; ## Message shown in login window
auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
autoindex on;
}
location /. { ## Disable .htaccess and other hidden files
return 404;
}
location #handler { ## Magento uses a common front handler
rewrite / /index.php;
}
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}
location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; }
expires off; ## Do not cache dynamic content
fastcgi_pass 127.0.0.1:9000;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default;
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
}
worked for me...
The problem was that "default" row had "https", and "stores" row had "http".
Use PhpMyAdmin to execute this SQL command:
SELECT * FROM `core_config_data` WHERE path like '%secure/base_url'
Then check that all secure rows start with "https".
Please check with your htaccess file. If it exists please check the existing rules
My current setup is running Ubuntu 12.04 LTS, Nginx 1.4.1, with Magento 1.7.0.2.
Earlier today, I set up a basic Magento store. I haven't installed any modules and I haven't made any configuration changes. I'm just looking to get the groundwork laid before delving further into the system. I am looking to remove the "index.php" that appears between the domain name and the file path.
My vhost is taken from the nginx website:
server {
root /path/to/root/domain/html;
index index.php;
error_log /path/to/error/log/error.log;
access_log /path/to/transfer/log/transfer.log;
server_name servername.com;
location / {
index index.html index.php;
try_files $uri $uri/ #handler;
expires 30d;
}
location ^~ /(app|includes|lib|media/downloadable|pkginfo|report/config.xml|var)/ { internal; }
location /var/export/ { internal; }
location /. { return 404; }
location #handler { rewrite / /index.php; }
location ~* .php/ { rewrite ^(.*.php)/ $1 last; }
location ~* .php$ {
if (!-e $request_filename) { rewrite / /index.php last; }
expires off;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default;
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params;
}
}
I see that other people have have been searching for the answer to this question, there are code snippets to solutions, but none of these appear to work with my system. When I make changes to my Nginx vhost, I always restart nginx, but index.php still shows up in the URL.
Nginx config looks fine. In system > configuration > general > web in your admin panel set Use Web Server Rewrites to yes and clear the cache in magento.
Add this to magento nginx vhost.
location / {
if (!-e $request_filename) {
rewrite ^/([^?]*)(?:\?(.*))? /index.php?title=$1&$2 last;
}
if ($uri ~* "\.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$") {
expires max;
break;
}
}
Hi I have a magento store at mysite.com
Now I want to setup a url that will run my german website at mysite.com/german
Using the same install. I already have a half working config, but my issue is that beyond the homepage all magento URLs 404. Here is my current config.
server {
listen 80;
server_name mysite.com www.mysite.com;
####
#
# BELOW THIS LINE IS MY ATTEMPT TO GET mysite.com/german to run from the same directory as mysite.com
#
####
location ~ /german(.*)\.php($|/) {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/www$1.php;
fastcgi_param MAGE_RUN_CODE german;
fastcgi_param MAGE_RUN_TYPE website;
}
location ~ /german(.*) {
index index.htm index.php;
autoindex off;
alias /usr/share/nginx/www$1;
}
location ~ /deutch/ {
index index.htm index.php;
try_files $uri $uri/ #handler;
}
The old config:
###
#
# THIS BIT I THINK IS THE PART WHICH IS NOT QUITE WORKING, BUT I DON'T KNOW WHAT THE #handler PART DOES
#
###
# This redirect is added so to use Magentos
# common front handler when handling incoming URLs.
location #handler {
rewrite / /index.php;
}
####
#
# BELOW THIS LINE IS THE ORIGINAL CONFIG WHICH RUNS mysite.com NO PROBLEMS
#
####
root /usr/share/nginx/www;
location / {
index index.htm index.php;
try_files $uri $uri/ #handler;
}
# Deny access to specific directories no one
# in particular needs access to anyways.
location /app/ { deny all; }
location /includes/ { deny all; }
location /lib/ { deny all; }
location /media/downloadable/ { deny all; }
location /pkginfo/ { deny all; }
location /report/config.xml { deny all; }
location /var/ { deny all; }
# Allow only those who have a login name and password
# to view the export folder. Refer to /etc/nginx/htpassword.
location /var/export/ {
auth_basic "Restricted";
auth_basic_user_file htpasswd;
autoindex on;
}
# Deny all attempts to access hidden files
# such as .htaccess, .htpasswd, etc...
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# This redirect is added so to use Magentos
# common front handler when handling incoming URLs.
location #handler {
rewrite / /index.php;
}
# Forward paths such as /js/index.php/x.js
# to their relevant handler.
location ~ .php/ {
rewrite ^(.*.php)/ $1 last;
}
# Handle the exectution of .php files.
location ~ .php$ {
if (!-e $request_filename) {
rewrite / /index.php last;
}
expires off;
fastcgi_pass 127.0.0.1:9000;
#fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE english;
fastcgi_param MAGE_RUN_TYPE website;
include fastcgi_params;
}
}
location ~* \.php$ {
if (!-e $request_filename) {
rewrite / /index.php last;
}
expires off;
set $runcode english;
set $runtype website;
if ( $request_uri ~* ^/german ) {
set $runcode german;
}
fastcgi_pass 127.0.0.1:9000;
#fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE $runcode;
fastcgi_param MAGE_RUN_TYPE $runtype;
include fastcgi_params;
}
That is part 1, part 2 is to ensure the code is run from the same codebase.
One solution is to symlink the directory to the root directory, exec the following in the /usr/share/nginx/www directory:
ln -s . ./german
It's filty, but it works ;)
We're using the following to redirect to the correct index file:
location /german {
if ( -e $request_filename ) {
break;
}
rewrite ^/german(.*)$ /german/index.php last;
}
#
# Redirection of subdirectory php's to their respective php files
#
location ~ .php/ {
rewrite ^(.*.php)/ $1 last;
}
#
# Redirect everything else to root path
#
location / {
try_files $uri $uri/ /index.php?$args;
}
This is nginx rewrite rule for codeigniter.
We can find this easily with googling.
server
{
server_name .example.com;
access_log /var/log/nginx/example.com.access.log;
root /var/www/example.com/html;
index index.php index.html index.htm;
# enforce www (exclude certain subdomains)
# if ($host !~* ^(www|subdomain))
# {
# rewrite ^/(.*)$ $scheme://www.$host/$1 permanent;
# }
# enforce NO www
if ($host ~* ^www\.(.*))
{
set $host_without_www $1;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}
# canonicalize codeigniter url end points
# if your default controller is something other than "welcome" you should change the following
if ($request_uri ~* ^(/welcome(/index)?|/index(.php)?)/?$)
{
rewrite ^(.*)$ / permanent;
}
# removes trailing "index" from all controllers
if ($request_uri ~* index/?$)
{
rewrite ^/(.*)/index/?$ /$1 permanent;
}
# removes trailing slashes (prevents SEO duplicate content issues)
if (!-d $request_filename)
{
rewrite ^/(.+)/$ /$1 permanent;
}
# removes access to "system" folder, also allows a "System.php" controller
if ($request_uri ~* ^/system)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
# unless the request is for a valid file (image, js, css, etc.), send to bootstrap
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
# catch all
error_page 404 /index.php;
# use fastcgi for all php files
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/example.com/html$fastcgi_script_name;
include fastcgi_params;
}
# deny access to apache .htaccess files
location ~ /\.ht
{
deny all;
}
}
I want to add normal php project in this server.
The project's root directory is /var/www/another/proj_new.
As I mentioned, this new project do not use codeigniter frame.
This is normal php file project. So it doesn't need Codeigniter rewrite rule.
So, my question is is possible that I can access the new project through the web.
the address may be like this:
http://example.com/proj_new
This address should not call codeigniter's proj_new controller.
I've tried to add this setting :
server
{
....
....
....
localhost /proj_new {
root /var/www/another/proj_new
index index.php
}
....
....
....
}
but, http://example.com/proj_new
makes 404 error pages.
I suggest this configuration from Nginx
server {
server_name nginxcodeigniter.net;
root /var/www/codeigniter;
index index.html index.php;
# set expiration of assets to MAX for caching
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}
location / {
# Check if a file exists, or route it to index.php.
try_files $uri $uri/ /index.php;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
After this, make sure that your codeIgniter config.php contains the following information:
$config['base_url'] = "http://nginxcodeigniter.net/";
$config['index_page'] = "";
$config['uri_protocol'] = "REQUEST_URI";
Source: Nginx
The !-e in the following section of code means that if the file, directory or symlink does not exist, redirect to use the rewrite rule. The fact that you have this present should be enough for you to just create a folder proj_new and the rewrite rule should be ignored.
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
I presume you have tried just creating the proj_new folder already? It looks to me as if you already have sufficient means to achieve what you want in your file and I can't see any errors with it. You are creating your proj_new folder inside the html folder, right?
Just had a play about with this and it works fine. Your configuration works as expected. Attached below is my nginx.conf file so you can have a look. This was CI2.1, Nginx 1.0.1 Stable, Windows 7, PHP 5.3.1.
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
index index.php index.html index.htm;
# enforce NO www
if ($host ~* ^www\.(.*))
{
set $host_without_www $1;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}
# canonicalize codeigniter url end points
# if your default controller is something other than "welcome" you should change the following
if ($request_uri ~* ^(/welcome(/index)?|/index(.php)?)/?$)
{
rewrite ^(.*)$ / permanent;
}
# removes trailing "index" from all controllers
if ($request_uri ~* index/?$)
{
rewrite ^/(.*)/index/?$ /$1 permanent;
}
# removes trailing slashes (prevents SEO duplicate content issues)
if (!-d $request_filename)
{
rewrite ^/(.+)/$ /$1 permanent;
}
# removes access to "system" folder, also allows a "System.php" controller
if ($request_uri ~* ^/system)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
# unless the request is for a valid file (image, js, css, etc.), send to bootstrap
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
# catch all
error_page 404 /index.php;
# use fastcgi for all php files
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to apache .htaccess files
location ~ /\.ht
{
deny all;
}
}
}
What version of nginx are you using? This should work on newer versions, with the try_files directive.
http://ericlbarnes.com/post/12197460552/codeigniter-nginx-virtual-host
server {
server_name .mysecondsite.com;
root /sites/secondpath/www;
index index.html index.php index.htm;
# set expiration of assets to MAX for caching
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}
location / {
# Check if a file exists, or route it to index.php.
try_files $uri $uri/ /index.php;
}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
s// try this change the "backend" with your projectname
location / {
# Check if a file or directory index file exists, else route it to index.php.
try_files $uri $uri/ /index.php;
}
# canonicalize url end points
# if your default controller is something other than "welcome" you should change the following
if ($request_uri ~* ^(/welcome(/index)?|/index(.php)?)/?$)
{
rewrite ^/backend/(.*)$ /backend/ permanent;
}
# removes trailing "index" from all controllers
if ($request_uri ~* index/?$)
{
rewrite ^/backend/(.*)/index/?$ /backend/$1 permanent;
}
# removes trailing slashes (prevents SEO duplicate content issues)
if (!-d $request_filename)
{
rewrite ^/backend/(.+)/$ /backend/$1 permanent;
}
# removes access to "system" folder
if ($request_uri ~* ^/system)
{
rewrite ^/backend/(.*)$ /backend/index.php?/$1 last;
break;
}
# unless the request is for a valid file (image, js, css, etc.), send to bootstrap
if (!-e $request_filename)
{
rewrite ^/backend/(.*)$ /backend/index.php?/$1 last;
break;
}
can you add:
Can access to "backend" folder
if ($request_uri ~* ^/backend)
{
rewrite ^/(.*)$ /backend/index.php?/$1 last;
break;
}