Nginx 404 error on every page with magento (except front page) - magento

i am breaking my head over this.
I have magento 1.8.1 and migrating this to a nginx server (from apache)
The main page does work, but when i try to go to a other page (like a category or product page) i get a 404 error from Nginx.
I can't get this solved.
I have php-fpm installed and running.
nginx version: nginx/1.1.19
and
PHP 5.3.10-1ubuntu3.12 (fpm-fcgi) (built: Jun 20 2014 00:40:17)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
with the ionCube PHP Loader v4.2.2, Copyright (c) 2002-2012, by ionCube Ltd.
My nginx.conf:
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
##
# Basic Settings
##
server_tokens off;
sendfile on;
keepalive_timeout 5;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
map $scheme $fastcgi_https { ## Detect when HTTPS is used
default off;
https on;
}
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log notice;
rewrite_log on;
log_format main ?$remote_addr - $remote_user [$time_local] $request ?
??$status? $body_bytes_sent ?$http_referer? ?
??$http_user_agent? ?$http_x_forwarded_for??;
##
# Gzip Settings
##
gzip on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
My site.conf:
server {
listen 80 default_server;
server_name xxx.stratoserver.net www.xxx.stratoserver.net; # like ServerName in Apache
root /var/www/vhosts/path_to; # document root
autoindex off; # we don’t want users to see files in directories
#ensure sensitive files are not accessible
location ~ (^/(app/\|includes/\|lib/\|/pkginfo/\|var/\|report/config.xml)\|/\.svn/\|/\.git/\|/.hta.+) {
deny all; }
location / {
index index.php index.html index.htm;
try_files $uri $uri/ #handler; ## If missing pass the URI to Magento's front handler
expires 30d; ## Assume all files are cachable
if ($request_filename ~* ^.*?/([^/]*?)$)
{
set $filename $1;
}
if ($filename ~* ^.*?\.(eot)|(ttf)|(woff)$){
add_header Access-Control-Allow-Origin *;
}
}
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires 360d;
}
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;
}
}
Who can help me to get the rest of the website running.
The phpinfo.php file does work.

I had also same problem.
use link like this : magento181/index.php/prodct
instade of : magento181/product
This is url rewriting problem..

Related

How to fix 403 Forbidden nginx/1.16.1

I am trying to run a Larevel project on this Nginx server. When I access project/public file via the web browser I get
403 Forbidden
nginx/1.16.1
Inside my public file, files look like this
How can I fix this?
PS: Just for the curiosity I renamed index.php file to index.html and accessed project/public via web browser. Then it shows me the code instead of giving 403 Error.
Here is the Nginx conf file.
user daemon daemon;
worker_processes auto;
error_log "/opt/bitnami/nginx/logs/error.log";
pid "/opt/bitnami/nginx/logs/nginx.pid";
events {
use epoll;
worker_connections 1024;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
client_body_temp_path "/opt/bitnami/nginx/tmp/client_body" 1 2;
proxy_temp_path "/opt/bitnami/nginx/tmp/proxy" 1 2;
fastcgi_temp_path "/opt/bitnami/nginx/tmp/fastcgi" 1 2;
scgi_temp_path "/opt/bitnami/nginx/tmp/scgi" 1 2;
uwsgi_temp_path "/opt/bitnami/nginx/tmp/uwsgi" 1 2;
access_log "/opt/bitnami/nginx/logs/access.log";
sendfile on;
keepalive_timeout 65;
client_max_body_size 80M;
gzip on;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_proxied any;
gzip_vary on;
gzip_types text/plain
text/xml
text/css
text/javascript
application/json
application/javascript
application/x-javascript
application/ecmascript
application/xml
application/rss+xml
application/atom+xml
application/rdf+xml
application/xml+rss
application/xhtml+xml
application/x-font-ttf
application/x-font-opentype
application/vnd.ms-fontobject
image/svg+xml
image/x-icon
application/atom_xml;
gzip_buffers 16 8k;
add_header X-Frame-Options SAMEORIGIN;
ssl_prefer_server_ciphers on;
gzip on;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_proxied any;
gzip_vary on;
gzip_types text/plain
text/xml
text/css
text/javascript
application/json
application/javascript
application/x-javascript
application/ecmascript
application/xml
application/rss+xml
application/atom+xml
application/rdf+xml
application/xml+rss
application/xhtml+xml
application/x-font-ttf
application/x-font-opentype
application/vnd.ms-fontobject
image/svg+xml
image/x-icon
application/atom_xml;
gzip_buffers 16 8k;
add_header X-Frame-Options SAMEORIGIN;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS;
include "/opt/bitnami/nginx/conf/bitnami/bitnami.conf";
}
This is the nginx.conf.default file
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
location ~ \.php$ {
proxy_pass http://127.0.0.1;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
You're declaring to pass .php files to Apache, then you're declaring to use a fastcgi service on 127.0.0.1:9000:
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
location ~ \.php$ {
proxy_pass http://127.0.0.1;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
First, you probably want to remove the Apache reference. Then you need to check your fastcgi backend configuration, as your nginx are "passing" all the php request to it.
You're declaring also fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; and this mean that your php scripts are searched in /scripts folder. Is this right? If you want to keep your PHP files in html folder you nedd to change this line with fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;. Check also what's inside file fastcgi_params, as this file is included and so you're loading pieces of configuration from it.
I suppose you're using php-fpm, I can suggest also to change the configuration in order to use a socket file instead of a TCP connection:
fastcgi_pass unix:/var/run/php5-fpm.sock;
And change listen = 127.0.0.1:9000 with listen = /var/run/php5-fpm.sock in your php-fpm configuration.

Cache Zend Framework homepage on nginx

I have zend framework 1.12 based site working with nginx
I installed wnmp on windows 7 professional to test Windows, nginx, mariadb, php7
I want to cache home page which is localhost or localhost/
which internally calls index.php using index.php
similarly urls http://localhost/conference/sessions/date/2015-04/12/page/1 conference - controller sessions - action request params date, and page with respective values
I want to cache home page but I have looked but nothing specific is available
Here is my nginx.conf that works without caching
here is what I have in my nginx.conf
worker_processes 1;
error_log logs/error.log;
pid logs/nginx.pid;
events {
# Max value 16384
worker_connections 8192;
# Accept multiple connections
multi_accept on;
}
# Settings that affect all server blocks
http {
include php_processes.conf;
include mime.types;
default_type application/octet-stream;
access_log logs/access.log;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
sendfile on;
keepalive_timeout 65;
ssl_session_timeout 10m;
ssl_protocols TLSv1.2 TLSv1.1 TLSv1 SSLv3;
ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AES:RSA+3DES:!ADH:!AECDH:!MD5:!DSS;
ssl_prefer_server_ciphers on;
gzip on;
# http server
# Begin HTTP Server
server {
listen 80; # IPv4
server_name localhost;
## Parametrization using hostname of access and log filenames.
access_log logs/localhost_access.log;
error_log logs/localhost_error.log;
## Root and index files.
root html;
index index.php index.html index.htm;
## If no favicon exists return a 204 (no content error).
location = /favicon.ico {
try_files $uri =204;
log_not_found off;
access_log off;
}
## Don't log robots.txt requests.
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
## Try the requested URI as files before handling it to PHP.
location / {
## Regular PHP processing.
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass php_processes;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
## Static files
location ~* \.(?:css|gif|htc|ico|js|jpe?g|png|swf)$ {
expires max;
log_not_found off;
## No need to bleed constant updates. Send the all shebang in one
## fell swoop.
tcp_nodelay off;
## Set the OS file cache.
open_file_cache max=1000 inactive=120s;
open_file_cache_valid 45s;
open_file_cache_min_uses 2;
open_file_cache_errors off;
}
## Keep a tab on the 'big' static files.
location ~* ^.+\.(?:ogg|pdf|pptx?)$ {
expires 30d;
## No need to bleed constant updates. Send the all shebang in one
## fell swoop.
tcp_nodelay off;
}
try_files $uri $uri/ #missing;
} # / location
location #missing {
rewrite (.*) /index.php;
}
}
Please help.
Added Under http
note - add two underscores (__) if you cookie starts with and underscore (_)
fastcgi_cache_path /home/k47/cache/nginx levels=1:2 keys_zone=MYHOMEPAGE:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_method$query_string$request_uri$cookie_one$cookie_two$cookie__ga$cookie__gat";
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_cache_valid 200 302 1m;
Under server set a flag/variable which can be used to determine if we need caching or not
I have used other urls to cache and not cache with similar regex
set $no_cache 1;
if ($request_uri ~* "^/$")
{
set $no_cache 0;
}
then finally under location {} I start with
fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;
fastcgi_cache MYHOMEPAGE;
fastcgi_cache_valid 200 1m;
add_header X-Proxy-Cache $upstream_cache_status;
add_header cache-control 'public, max-age=500';

wnmp nginx configuration for Zend Framework 1.12 (Windows, nginx, mariadb, php 7)

I have zend framework 1.12 based site with .htaccess content as follows
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
I installed wnmp on windows 7 professional to test Windows, nginx, mariadb, php7
The home page on local host works great. PHP 7 and mariaDB worked great and showed data nd images on the home page localhost ( http://localhost )
I tried many things also stackoverflow's example Apache rewrite rule to NGINX for HHVM
My urls for the host straight forward
like
http://localhost/conference/sessions/date/2015-04/12/page/1
conference - controller
sessions - action
request params date, and page with respective values
here is what I have in my nginx.conf
worker_processes 1;
error_log logs/error.log;
pid logs/nginx.pid;
events {
# Max value 16384
worker_connections 8192;
# Accept multiple connections
multi_accept on;
}
# Settings that affect all server blocks
http {
include php_processes.conf;
include mime.types;
default_type application/octet-stream;
access_log logs/access.log;
sendfile on;
keepalive_timeout 65;
ssl_session_timeout 10m;
ssl_protocols TLSv1.2 TLSv1.1 TLSv1 SSLv3;
ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AES:RSA+3DES:!ADH:!AECDH:!MD5:!DSS;
ssl_prefer_server_ciphers on;
gzip on;
# http server
# Begin HTTP Server
server {
listen 80; # IPv4
server_name localhost;
## Parametrization using hostname of access and log filenames.
access_log logs/localhost_access.log;
error_log logs/localhost_error.log;
## Root and index files.
root html;
index index.php index.html index.htm;
## If no favicon exists return a 204 (no content error).
location = /favicon.ico {
try_files $uri =204;
log_not_found off;
access_log off;
}
## Don't log robots.txt requests.
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
## Try the requested URI as files before handling it to PHP.
location / {
## Regular PHP processing.
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass php_processes;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
## Static files
location ~* \.(?:css|gif|htc|ico|js|jpe?g|png|swf)$ {
expires max;
log_not_found off;
## No need to bleed constant updates. Send the all shebang in one
## fell swoop.
tcp_nodelay off;
## Set the OS file cache.
open_file_cache max=1000 inactive=120s;
open_file_cache_valid 45s;
open_file_cache_min_uses 2;
open_file_cache_errors off;
}
## Keep a tab on the 'big' static files.
location ~* ^.+\.(?:ogg|pdf|pptx?)$ {
expires 30d;
## No need to bleed constant updates. Send the all shebang in one
## fell swoop.
tcp_nodelay off;
}
} # / location
}
# End HTTP Server
# Begin HTTPS Server
server {
listen 443 http2 ssl;
server_name localhost;
ssl_certificate cert.pem;
ssl_certificate_key key.pem;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
## Parametrization using hostname of access and log filenames.
access_log logs/localhost_access.log;
error_log logs/localhost_error.log;
## Root and index files.
root html;
index index.php index.html index.htm;
## If no favicon exists return a 204 (no content error).
location = /favicon.ico {
try_files $uri =204;
log_not_found off;
access_log off;
}
## Don't log robots.txt requests.
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
## Try the requested URI as files before handling it to PHP.
location / {
## Regular PHP processing.
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass php_processes;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
## Static files are served directly.
location ~* \.(?:css|gif|htc|ico|js|jpe?g|png|swf)$ {
expires max;
log_not_found off;
## No need to bleed constant updates. Send the all shebang in one
## fell swoop.
tcp_nodelay off;
## Set the OS file cache.
open_file_cache max=1000 inactive=120s;
open_file_cache_valid 45s;
open_file_cache_min_uses 2;
open_file_cache_errors off;
}
## Keep a tab on the 'big' static files.
location ~* ^.+\.(?:ogg|pdf|pptx?)$ {
expires 30d;
## No need to bleed constant updates. Send the all shebang in one
## fell swoop.
tcp_nodelay off;
}
} # / location
} # End HTTPS Server
}
Please help me with this one; I am new to nginx.
try to add in server configuration server {...} redirection to index.php for resources that are not found
try_files $uri #missing;
location #missing {
rewrite .* /index.php;
}
root ...; should point to public directory that contain index.php

Joomla with Nginx Rewrite SEF url

I am using Ubuntu 12.04 with NGINX and PHP5-FPM. I've just migrated my Joomla website from Apache to NGINX. But i think rewrite rules are not working well.
All of the SEF links rewrite to the homepage, but in the url bar link seems right.
Example if i click example.com/a/b.html it looks like go to the link in the url bar but homapage is loading.
Thanks for your help.
/etc/nginx/sites-available/example.com file
server {
listen 80;
server_name example.com;
#server_name_in_redirect off;
#access_log /var/log/nginx/localhost.access_log main;
#error_log /var/log/nginx/localhost.error_log info;
root /var/www/example.com/public_html/;
index index.php index.html index.htm default.html default.htm;
# Support Clean (aka Search Engine Friendly) URLs
location / {
try_files $uri $uri/ /index.php?q=$request_uri;
}
# deny running scripts inside writable directories
location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
return 403;
error_page 403 /403_error.html;
}
location ~ \.php$ {
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
#fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# caching of files
location ~* \.(ico|pdf|flv)$ {
expires 1y;
}
location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
expires 14d;
}
}
nginx.conf
user www-data;
worker_processes 8;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 30;
types_hash_max_size 2048;
server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
gzip_vary on;
# gzip_proxied any;
gzip_comp_level 6;
# gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
## Block spammers and other unwanted visitors ##
include /etc/nginx/blockips.conf;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Yes - this reply is over 3 years old, but, unfortunately, the same problem exists on the latest version of Joomla when using NGINX...
We had the exact same problem on one of our client's sites. The problem turned out to be related to one of PHP's $_SERVER constants not being set by the NGINX server - and that constant (which is `$_SERVER['PHP_SELF']) is used in many places in Joomla to return the current URL. We have described, in details, the problem and how to fix it, here.
if you're using subfolder / virtual hosts, try changing:
# Support Clean (aka Search Engine Friendly) URLs
location / {
try_files $uri $uri/ /index.php?q=$request_uri;
}
To
# Support Clean (aka Search Engine Friendly) URLs
location /subfolder/ {
try_files $uri $uri/ /subfolder/index.php?q=$request_uri;
}
Hello this is my host configuration, wich is working fine with with Joomla 3.6.5 friendly URLs, Ubuntu 16.04 , PHP7 and nginx:
server {
listen 80;
server_name mydomain.com;
root /var/www/html/mydomain;
index index.php index.html index.htm default.html default.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
}
My solution was to make sure that this part of the php.ini is enabled: cgi.fix_pathinfo = 1. This fixed the problem that $_SERVER['PHP_SELF'] was not set.
I had it disabled by accident.
cgi.fix_pathinfo provides real PATH_INFO/PATH_TRANSLATED support for CGI. PHP's previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting of zero causes PHP to behave as before. Default is 1. You should fix your scripts to use SCRIPT_FILENAME rather than PATH_TRANSLATED. http://php.net/cgi.fix-pathinfo

How To Rewrite Nginx For Multi-Language SEO URLs For Magento

I'm developing a multi-language Magento on Nginx with fastcgi. Everything is working except I can't seem to get the URLs like I had with Apache.
I would like to remove index.php from the url. Example:
/es/index.php/category.html to
/es/category.html
also in english
/index.php/category.html to
/category.html
That's all.
Additional Info:
I have tried to set "Use Web Server Rewrites" in administration to yes. And this works but only for English i.e. default but then I get 404 for Spanish, except on the Home page!
If I set "Use Web Server Rewrites" in administration to no, then everything works good except it adds index.php to the URLs. But if I manually remove the index.php from the URL the page still goes to 404.
Also, in Magento Administration I have Base URL settings like this: https://www.examplesite.com/es/ and {{secure_base_url}}../skin/ etc.
I have a file folder in my root /es/ with a copy of the index.php like this:
/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
Mage::run('es');
Here is my Config for Nginx:
worker_processes 1;
error_log /mba/nginx/logs/error.log;
pid /mba/nginx/logs/nginx.pid;
events {
worker_connections 2048;
}
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 64;
open_file_cache max=100 inactive=1m;
open_file_cache_valid 20s;
open_file_cache_min_uses 1;
open_file_cache_errors on;
fastcgi_buffers 256 4k;
ignore_invalid_headers on;
client_header_buffer_size 1k;
client_body_buffer_size 64k;
large_client_header_buffers 4 8k;
client_body_timeout 60;
client_header_timeout 60;
keepalive_requests 100;
keepalive_timeout 300 300;
keepalive_disable msie6;
send_timeout 60;
max_ranges 1;
reset_timedout_connection on;
sendfile on;
sendfile_max_chunk 512k;
server_tokens off;
log_format main '$remote_addr - $remote_user [$time_local] "$request "'
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /mba/nginx/logs/access.log main;
autoindex off;
map $scheme $fastcgi_https { ## Detect when HTTPS is used
default off;
https on;
}
gzip on;
gzip_static on;
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
gzip_comp_level 2;
gzip_min_length 0;
gzip_proxied any;
gzip_types text/plain image/x-icon image/bmp text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
proxy_buffering on;
#proxy_cache_path /mba/nginx/proxy levels=1:2 keys_zone=one:15m inactive=7d max_size=1000m;
proxy_buffer_size 4k;
proxy_buffers 100 16k;
proxy_connect_timeout 60;
proxy_send_timeout 60;
proxy_read_timeout 60;
#include /mba/nginx/conf.d/*.conf;
##
# SSL Support
##
map $scheme $fastcgi_https {
default off;
https on;
}
server {
listen 80;
#listen 443 default ssl;
expires max;
add_header Cache-Control public;
#ssl_certificate /openssl/ssl/www_mybelovedangels_com.crt;
#ssl_certificate_key /openssl/ssl/www_mybelovedangels_com.key;
#access_log /mba.nginx.1/mba/nginx/logs/access_log;
root /mba.nginx.1/mba/www;
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires +60d;
log_not_found off;
}
location / {
index index.html index.php;
try_files $uri $uri/ #handler;
expires +30d;
deny 192.168.1.1;
allow 192.168.1.0/24;
allow 127.0.0.1;
allow 2620:100:e000::8001;
deny all;
}
# 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 en;
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params;
}
}
}
I hope this isn't to much information but it might be needed. I've looked everywhere on the net I couldn't find and there is nothing I can understand about how to do this.
Thanks
Edit your vhost config file for this domain and add the following:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
then make sure Magento is setup to exclude index.php from the urls this should happen when you enable Use Web Server Rewrites
I've created a virtual host and chaged my config like this:
#user nginx;
worker_processes 1;
error_log /mba/nginx/logs/error.log;
pid /mba/nginx/logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 64;
log_format main '$remote_addr - $remote_user [$time_local] "$request "'
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /mba/nginx/logs/access.log main;
sendfile on;
autoindex off;
map $scheme $fastcgi_https { ## Detect when HTTPS is used
default off;
https on;
}
keepalive_timeout 10;
gzip on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
# Load config files from the /etc/nginx/conf.d directory
include /mba/nginx/conf.d/*.conf;
}
and my virtual file like:
server {
listen 80;
server_name myexamplesite.com;
rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
}
server {
listen 80 default;
## SSL directives might go here
server_name www.myexamplesite.com *.myexamplesite.com; ## myexamplesite is here twice so server_name_in_redirect will favour the www
root /mba/www/myexamplesite.com;
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$ { ## 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 127.0.0.1:9000;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE en; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
}
The problem with this configuation is the links "download" when clicking on them and don't change pages . No errors in NginX, PHP, Magento system or database logs thou.
im a bit lost in your settings, but ok, you have to dynamically map your store code in nginx, but now you have "en" hard-coded. just wrap all your configs, backup, and start over. nginx is a bit messy, do not go ahead creating hard-wrong-nonstandard-configurations. make it simple, like per magento manual, but step by step.
ADM
I have the new config working like this:
#user www-data;
worker_processes 1; ## = CPU qty
error_log /mba/nginx/logs/error.log;
#error_log /mba/nginx/logs/error.log notice;
#error_log /mba/nginx/logs/error.log info;
pid /mba/nginx/logs/nginx.pid;
events {
worker_connections 1024;
# use epoll;
}
http {
index index.html index.php; ## Allow a static html file to be shown first
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#log_format error403 '$remote_addr - $remote_user [$time_local] '
# '$status "$request" "$http_x_forwarded_for"';
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_types text/css application/x-javascript;
gzip_buffers 16 8k;
gzip_comp_level 8;
gzip_min_length 1024;
keepalive_timeout 15;
## Use when Varnish in front
#set_real_ip_from 127.0.0.1;
#real_ip_header X-Forwarded-For;
## Multi domain configuration
#map $http_host $storecode {
#www.myexamplesite.com 1store_code; ## US main
#www.myexamplesite.net 2store_code; ## EU store
#www.domain3.de 3store_code; ## German store
#www.domain4.com 4store_code; ## different products
#}
server {
listen 80; ## change to 8080 with Varnish
#listen 443 ssl;
server_name www.myexamplesite.com *.myexamplesite.com; ## Domain is here
root /mba/www;
access_log /mba/nginx/access.log main;
## Nginx will not add the port in the url when the request is redirected.
#port_in_redirect off;
## SSL directives go here
##ssl_certificate = cat server.crt bundle.ca.crt >> www_server_com.chained.crt
#ssl_certificate /etc/ssl/certs/www_server_com.chained.crt;
#ssl_certificate_key /etc/ssl/certs/server.key;
#ssl_session_cache shared:SSL:15m;
#ssl_session_timeout 15m;
#ssl_protocols SSLv3 TLSv1;
#ssl_ciphers HIGH:!ADH:!EXPORT56;
#ssl_prefer_server_ciphers on;
## Server maintenance block. insert dev ip 1.2.3.4 static address www.whatismyip.com
#if ($remote_addr !~ "^(1.2.3.4|1.2.3.4)$") {
#return 503;
#}
#error_page 503 #maintenance;
#error_page 403 /403.html;
#location #maintenance {
#rewrite ^(.*)$ /error_page/503.html break;
#internal;
#access_log off;
#log_not_found off;
#}
#location = /403.html {
#root /var/www/html/error_page;
#internal;
#access_log /var/log/nginx/403.log error403;
#}
location / {
try_files $uri $uri/ #handler;
}
## These locations would be hidden by .htaccess normally
location ~ (/(app/|includes/|/pkginfo/|var/|errors/local.xml)|/\.svn/|/.hta.+) {
deny all;
#internal;
}
## Protecting /admin/ and /downloader/ 1.2.3.4 = static ip addresses (www.whatismyip.com)
#location /downloader { allow 1.2.3.4; allow 1.2.3.4; deny all; rewrite ^/downloader/(.*)$ /downloader/index.php$1;}
#location /admin { allow 1.2.3.4; allow 1.2.3.4; deny all; rewrite / /#handler;}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location #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
add_header X-Config-By 'MagenX -= www.magentomod.com =-';
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param MAGE_RUN_CODE $storecode; ## Store code with multi domain
fastcgi_param MAGE_RUN_CODE en;
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
}
}
In MAGE_RUN_CODE I still have to add "en" because it doesn't work with "default"
I'm planning on using this: Zoom Full-Page Cache because I tried it and it really made a major improvement in the speed of my pages. He says it can be configured for multi-languages. It messes up a few little places on some of my pages thou. I'm sure it's just because I didn't have it "Punching Holes" :) correctly. I have a lot of extra extensions installed.
The reason I mention it is I'm not sure if I should have Zoom installed first because on his site he gives some code to add to your NginX config. That's where I learned about NginX from. So I thought I would unistall his Zoom and get everything set correctly then reinstall it. Don't know really.
Anyway, I noticed in this new config here:
#map $http_host $storecode {
#www.myexamplesite.com 1store_code; ## US main
#www.myexamplesite.net 2store_code; ## EU store
#www.domain3.de 3store_code; ## German store
#www.domain4.com 4store_code; ## different products
#}
It looks like I might have to have a new domain name for each language?

Resources