Welcome! Log In Create A New Profile

Advanced

Nginx vhost config issue

Posted by rahilmaknojia 
Nginx vhost config issue
January 07, 2014 10:08AM
I am migrating my store from apache to Nginx due to memory and performance concerns. I configured vhost file for http and https, but somehow I am not able redirect http://www.domain.com/admin to https://www.domain.com/admin.

On login window, it prompts me to login and I was able to login successfully, but it doesnt redirect from http to https before login. After login it redirects to https without any certification issue.

Certificate is valid as I am able to browse normal pages in https by typing in manually.

Here is my config file:

server {
listen 80;
server_name www.domain.com domain.com;
root /var/vhost/www/domain.com/public_html/;
index index.html index.php;

access_log /var/vhost/www/domain.com/logs/access_log;
error_log /var/vhost/www/domain.com/logs/error_log;
listen 443 ssl;
ssl_certificate /var/vhost/www/domain.com/ssl/www_domain_com_ee.crt;
ssl_certificate_key /var/vhost/www/domain.com/ssl/domain.com.np.key;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
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/ {
auth_basic "Restricted";
auth_basic_user_file htpasswd;
autoindex on;
}
location /. {
return 404;
}

location @handler {
rewrite / /index.php;
}

location ~ .php/ {
rewrite ^(.*.php)/ $1 last;
}

location ~ \.php$ {
try_files $uri =404;
expires off;
fastcgi_read_timeout 900s;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param HTTPS on;
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 /etc/nginx/fastcgi_params;
}
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 /lib/minify/ {
allow all;
}
gzip on;
#gzip_comp_level 9;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain application/xml text/css text/js application/x-javascript;
}

Would really appreciate your help smile

Thanks
Re: Nginx vhost config issue
January 10, 2014 06:18PM
Why should it redirect to https when you open http://www.domain.com/admin ? I don't see any "location /admin" block that would do that.

If you want https only for /admin create a block like this:

location /admin {
return 301 https://www.domain.com/admin;
}

Better: If you have the ressources, why not redirect all traffic to https?

server {
listen 80;
server_name www.domain.com domain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name www.domain.com domain.com;

[rest of your config]
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 299
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready