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;
}
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 am struggling to get my virtual host working with magento2.
Can anyone help?
server {
listen 80;
server_name local.magento2.com;
root /home/www/magento2/;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
index index.php;
try_files $uri $uri/ #handler; ## If missing pass the URI to Magento's front handler
expires off; ## Assume all files are cachable
}
location #handler { ## Magento uses a common front handler
rewrite / /index.php;
}
location /pub/static {
rewrite ^/pub/static/(.*)$ /pub/static.php?resource=$1? last;
}
# Foward php request to FastCGI server.
location ~ \.php$ {
#if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
fastcgi_pass php5-fpm-sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
Here is what seems to be an official magento2 nginx configuration.
upstream fpm_backend {
server 127.0.0.1:9000; # backend server:port address
}
server {
listen 80 default;
server_name magento.lan www.magento.lan;
root /var/www/magento2; # document root, path to directory with files
index index.html index.php;
autoindex off; # we don’t want users to see files in directories
location ~ (^/(app/\|includes/\|lib/\|/pkginfo/\|var/\|report/config.xml)\|/\.svn/\|/\.git/\|/.hta.+) {
deny all; #ensure sensitive files are not accessible
}
location / {
try_files $uri $uri/ /index.php?$args; # make index.php handle requests for /
access_log off; # do not log access to static files
expires max; # cache static files aggressively
}
location \~\* \.(jpeg\|jpg\|gif\|png\|css\|js\|ico\|swf)$ {
try_files $uri $uri/ #proxy; # look for static files in root directory and
ask backend if not successful
expires max;
access_log off;
}
location #proxy {
fastcgi_pass fpm_backend; # proxy everything from this location to backend
}
location \~\.php$ {
try_files $uri =404; # if reference to php executable is invalid return 404
expires off; # no need to cache php executable files
fastcgi_read_timeout 600;
fastcgi_pass fpm_backend; # proxy all requests for dynamic content to
# backend configured in upstream.conf
fastcgi_keep_conn on; # use persistent connects to backend
include fastcgi_params;
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;
}
}
I can't access PHP files placed in sub-directories and my CSS/JS files return a 404 in browser. Yes, I have seen many others experiencing a 404 issue but their fixes don't seem to be my solution. I've also swapped out my configuration with several online. Here is my configuration:
server {
# Port that the web server will listen on.
listen 80;
# Host that will serve this project.
server_name .stackoverflow.com;
# Useful logs for debug.
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
rewrite_log on;
# The location of our projects public directory.
root /usr/share/nginx/html/public;
# Point index to the Laravel front controller.
index index.php;
location / {
# URLs to attempt, including pretty ones.
try_files $uri $uri/ /index.php?$query_string;
}
# Remove trailing slash to please routing system.
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
# PHP FPM configuration.
location ~* \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# We don't need .ht files with nginx.
location ~ /\.ht {
deny all;
}
# Set header expirations on per-project basis
location ~* \.(?:ico|css|js|jpe?g|JPG|png|svg|woff)$ {
expires 365d;
}
}
Is there something wrong with my configuration?
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
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