I think NGINX isn't serving magento CSS & JS files from the correct location my root is */data/www/public_html/hotnstylish/public/* but nginx seems to think its /etc/nginx/html !?? the frontend and backend both load with no style at all any clues would be great!
Part of my NGINX Error Log:
2013/11/20 23:26:08 [error] 13982#0: *3 open() "/etc/nginx/html/js/calendar/calendar.js" failed (2: No such file or directory), client: 89.168.219.134, server: 836237.vps-10.com, request: "GET /js/calendar/calendar.js HTTP/1.1", host: "836237.vps-10.com", referrer: "http://836237.vps-10.com/index.php/admin/dashboard/index/key/d6a8576bd8743279b6812c60ccd6b464/"
2013/11/20 23:26:08 [error] 13982#0: *5 open() "/etc/nginx/html/js/calendar/calendar-setup.js" failed (2: No such file or directory), client: 89.168.219.134, server: 836237.vps-10.com, request: "GET /js/calendar/calendar-setup.js HTTP/1.1", host: "836237.vps-10.com", referrer: "http://836237.vps-10.com/index.php/admin/dashboard/index/key/d6a8576bd8743279b6812c60ccd6b464/"
My vhost config file is as follows (messy as hell):
server {
listen 80;
server_name 836237.vps-10.com;
root /data/www/public_html/hotnstylish/public/;
access_log /data/www/public_html/hotnstylish/log/access.log;
error_log /data/www/public_html/hotnstylish/log/error.log;
location / {
root /data/www/public_html/hotnstylish/public/;
index index.html index.htm index.php;
try_files $uri $uri/ #handler; ## If missing pass the URI to Magento's front handler
expires 30d; ## Assume all files are cachable
include /etc/nginx/mime.types;
}
# error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
# location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
## 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 ~ \.css {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type application/x-javascript;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
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;
root /data/www/public_html/hotnstylish/public/;
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;
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
}
My Ngingx.conf:
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
#include /etc/nginx/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 /var/log/nginx/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/html 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 /etc/nginx/conf.d/*.conf;
#Load vHosts file for each site separately
include /etc/nginx/sites-enabled/*;
}
Make sure that your request processed in right server_name context.
If you use nginx ≥0.8.21 try to set
listen 80 default_server;
server_name 836237.vps-10.com;
Related
I have a simple Laravel route to provide to our users private files. We present files to users with the help of a middleware. Thus, we check whether the logged in user really has access to this file.
Everything is working as expected we on local environment. But we ran into a problem when we deployed it to the server. It does not see the Laravel route file in the Nginx location and tries to find the file in the root directory.
Laravel route example as below.
Route::get('lesson-attachment/{uuid}/{filename}', LessonAttachmentController::class)->name('lesson.attachment');
As you can see, we expect to receive a uuid and filename as url parameters. Actually the filaname parameter is required because we returns inline response on the exact url sometimes and we want to show the filename on the browser tab. Anyway, finally the codes here work fine on local machine.
But when we come to the nginx server, things get confused and when we look at the logs, we get the following error.
/var/www/vhosts/example.com/httpdocs/current/public/lesson-attachment/61cd7c8b-a7a1-49f8-86b8-d82825c9f55a/sample-file.pdf" failed (2: No such file or directory)
Here is the nginx conf:
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
The question is how can I run that url path on production server?
https://example.com/lesson-attachment/61cd7c8b-a7a1-49f8-86b8-d82825c9f55a/sample-file.pdf
For more information my development environment:
Macbook Pro
Laravel Valet
For more information our production environment:
Ubuntu 20
Nginx
Plesk Panel (core nginx configurations are provided from plesk)
Using php deployer tool for deployment to production.
UPDATE - The base server blocks of nginx configuration. Please note, it provides by Plesk.
#ATTENTION!
#
#DO NOT MODIFY THIS FILE BECAUSE IT WAS GENERATED AUTOMATICALLY,
#SO ALL YOUR CHANGES WILL BE LOST THE NEXT TIME THE FILE IS GENERATED.
map $sent_http_content_type $expires {
default off;
text/html epoch;
text/css max;
application/javascript max;
~image/ max;
~font/ max;
}
server {
listen ***** ssl http2;
expires $expires;
server_name example.com;
client_max_body_size 134217728;
# mailconfig
location ~* ^/autodiscover/autodiscover\.xml$ {
try_files $uri #mad;
}
location ~* ^(/\.well-known/autoconfig)?/mail/config\-v1\.1\.xml$ {
try_files $uri #mad;
}
location ~* ^/email\.mobileconfig$ {
try_files $uri #mad;
}
location #mad {
rewrite ^(.*)$ /mailconfig/ break;
proxy_pass http://127.0.0.1:8880;
proxy_set_header X-Host $host;
proxy_set_header X-Request-URI $request_uri;
}
# mailconfig
root "/var/www/vhosts/example.com/httpdocs/current/public";
access_log "/var/www/vhosts/system/example.com/logs/proxy_access_ssl_log";
error_log "/var/www/vhosts/system/example.com/logs/proxy_error_log";
#extension letsencrypt begin
location ^~ /.well-known/acme-challenge/ {
root /var/www/vhosts/default/htdocs;
types { }
default_type text/plain;
satisfy any;
auth_basic off;
allow all;
location ~ ^/\.well-known/acme-challenge.*/\. {
deny all;
}
}
#extension letsencrypt end
#extension sslit begin
#extension sslit end
#extension sectigo begin
location ^~ /.well-known/pki-validation/fileauth.txt {
try_files $uri $uri/ =404;
}
location ^~ /.well-known/pki-validation/ {
root /var/www/vhosts/default/htdocs;
types { }
default_type text/plain;
satisfy any;
auth_basic off;
allow all;
location ~ ^/\.well-known/pki-validation.*/\. {
deny all;
}
}
#extension sectigo end
error_page 400 "/error_docs/bad_request.html";
error_page 401 "/error_docs/unauthorized.html";
error_page 403 "/error_docs/forbidden.html";
error_page 404 "/error_docs/not_found.html";
error_page 500 "/error_docs/internal_server_error.html";
error_page 405 "/error_docs/method_not_allowed.html";
error_page 406 "/error_docs/not_acceptable.html";
error_page 407 "/error_docs/proxy_authentication_required.html";
error_page 412 "/error_docs/precondition_failed.html";
error_page 414 "/error_docs/request_uri_too_long.html";
error_page 415 "/error_docs/unsupported_media_type.html";
error_page 501 "/error_docs/not_implemented.html";
error_page 502 "/error_docs/bad_gateway.html";
error_page 503 "/error_docs/maintenance.html";
location ^~ /error_docs {
root "/var/www/vhosts/example.com";
}
location ~ /\.ht {
deny all;
}
location ~ ^/(plesk-stat|awstats-icon|webstat|webstat-ssl|ftpstat|anon_ftpstat) {
auth_basic_user_file "/var/www/vhosts/system/example.com/pd/d..httpdocs#plesk-stat";
autoindex on;
location ~ ^/plesk-stat(.*) {
alias /var/www/vhosts/system/example.com/statistics/$1;
}
location ~ ^/awstats-icon(.*) {
alias /usr/share/awstats/icon/$1;
}
location ~ ^/(.*) {
alias /var/www/vhosts/system/example.com/statistics/$1;
}
}
location ~ ^/~(.+?)(/.*?\.php)(/.*)?$ {
alias /var/www/vhosts/example.com/web_users/$1/$2;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
try_files $uri $fastcgi_script_name =404;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass "unix:/var/www/vhosts/system/example.com/php-fpm.sock";
include /etc/nginx/fastcgi.conf;
}
location ~ \.php(/.*)?$ {
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
try_files $uri $fastcgi_script_name =404;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass "unix:/var/www/vhosts/system/example.com/php-fpm.sock";
include /etc/nginx/fastcgi.conf;
}
index "index.html" "index.cgi" "index.pl" "index.php" "index.xhtml" "index.htm" "index.shtml";
disable_symlinks if_not_owner "from=/var/www/vhosts/example.com";
add_header X-Powered-By PleskLin;
include /etc/nginx/conf.d/expires.global;
include "/var/www/vhosts/system/example.com/conf/vhost_nginx.conf";
}
I use manjaro. I'm trying to deploy my site locally on the laravel framework. I use nginx server. When I go to the site page, I get the error: No input file specified. I think there is an error in the configuration files, but I don't know how to find it and fix it. Below are my configuration files
Nginx config file:
user mrgoodcat;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
#include /etc/nginx/sites-enabled/*;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
types_hash_max_size 4096;
server {
listen 80;
server_name localhost;
root /home/mrgoodcat/PhpstormProjects;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /home/mrgoodcat/PhpstormProjects;
index index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
root /usr/share/nginx/html;
include fastcgi.conf;
}
location = /favicon.ico {
access_log off;
log_not_found off;
}
#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 /home/mrgoodcat/PhpstormProjects;
}
}
## #note Load configs
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*.conf;
}
Site config file:
server {
listen 80;
listen [::]:80;
server_name project-a;
root /home/mrgoodcat/PhpstormProjects/project-a/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
I'm switching a Laravel Website from Apache (htaccess) to NGinx. I have built an Image Serving that produces a uri with the appropriate parameters for resizing ex : pics/images/max24h/music_video_red_icon.png.
I Apache does not find the file it would redirect it to a route image/images/max24h/music_video_red_icon.png where an Action in laravel creates and returns the image. In .htaccess it works with this code :
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^pics(.*)\.(jpe?g|png|gif|ico|bmp)$ /image$1.$2 [R=307,L]
Now in NGinx conf, How do I redirect it properly? I tried a lot of suggestions like :
# Redirect pics file not found to php laravel route to create the image
location #img_proxy {
rewrite ^/pics(.*)\.(jpe?g|png|gif|ico|bmp)$ /image$1.$2;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
It does not work at all, the server works if I remove those lines. I'm using Mac High Sierra 10.13.6 . Could it be some config conflict? Here is the full nginx.conf :
user _www _www;
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 default_server;
server_name localhost;
root /var/www/megalobiz/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
gzip on;
gzip_vary on;
gzip_disable "msie6";
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types
text/plain
text/css
text/js
text/xml
text/javascript
application/javascript
application/x-javascript
application/json
application/xml
application/xml+rss;
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
# removes trailing slashes (prevents SEO duplicate content issues)
#if (!-d $request_filename)
#{
# rewrite ^/(.+)/$ /$1 permanent;
#}
# Redirect pics file not found to php laravel route to create the image
location ~ ^/pics(.*)\.(jpe?g|png|gif|ico|bmp)$ {
try_files $uri #img_proxy;
}
location #img_proxy {
rewrite ^/pics(.*)\.(jpe?g|png|gif|ico|bmp)$ /image$1.$2;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|svg|woff|woff2|ttf)\$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
location ~* \.(?:css|js)\$ {
expires 7d;
access_log off;
add_header Cache-Control "public";
}
location ~ /\.(?!well-known).* {
deny all;
}
location ~ /\.ht {
deny all;
}
}
include servers/*;
}
The main difference between the function of the .htaccess file and your rewrite statement is that Apache will perform an external redirect using a 307 response, while Nginx performs an internal redirect instead. See this document for details.
To force Nginx to perform an external redirect, append the permanent or redirect flag to the rewrite statement, which generates a 301 or 302 response respectively.
For example:
location #img_proxy {
rewrite ^/pics(.*)\.(jpe?g|png|gif|ico|bmp)$ /image$1.$2 redirect;
}
The difference between a 302 and a 307 response, is that the latter will redirect a POST request method without changing it to a GET.
If you need to redirect POST requests, you will need to capture the relevant parts of the URI with a regular expression location or if block and use a return 307 instead.
For example:
location #img_proxy {
if ($uri ~ ^/pics(.*)\.(jpe?g|png|gif|ico|bmp)$) {
return 307 /image$1.$2$is_args$args;
}
}
See this caution on the use of if.
I am running magento under the Wordpress(Wordpress on the root and mangento under a subdirectory "/shop"). Previously I was running this under the Apache, So everything was running fine with separate .htaccess under the /shop folder.
As I move the server over NginX, all the internal magento URL showing 404. Please help me to solve this problem. Please suggest me how can I run the Magento under the /shop folder with Wordpress.
Here is my NginX Configuration file:
server {
listen 80;
server_name domain.com www.domain.com;
root /var/www/html;
index index.php index.html index.htm;
error_log /var/www/logs/error.log;
access_log /var/www/logs/access.log;
### gZip Setting ###
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;
### gZip End ###
location / {
if ($http_host !~ "^www\."){
rewrite ^(.*)$ http://www.$http_host/$1 redirect;
}
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location /shop/ {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}
if (!-e $request_filename)
{
rewrite ^(.+)$ /index.php?q=$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/php-fpm/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
}
I got the solution, Here is my new configuration file:
server {
listen 80;
server_name domain.com www.domain.com;
root /var/www/html;
index index.php index.html index.htm;
error_log /var/www/logs/domain-error-ssl.log;
access_log /var/www/logs/domain-access-ssl.log;
### gZip Setting ###
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;
### gZip End ###
location / {
if ($http_host !~ "^www\."){
rewrite ^(.*)$ https://www.$http_host/$1 redirect;
}
try_files $uri $uri/ /index.php?$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
rewrite ^(.*.php)/ $1 last;
}
### Configuration for shop ###
location /shop {
index index.html index.php;
try_files $uri $uri/ #handler;
expires 30d;
if ($uri ~ "^/index.php/admin.*$"){
rewrite ^/index.php/admin(.*) /admin$1 redirect;
}
}
location ~ ^/shop/(app|includes|lib|media/downloadable|pkginfo|report/config.xml|var)/ { internal; }
location /shop/var/export/ { internal; }
location #handler { rewrite / /shop/index.php; }
### END Configuration for shop ###
location ~ .php$ { ## Execute PHP scripts
expires off; ## Do not cache dynamic content
fastcgi_read_timeout 120;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
#fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
}
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?