301 redirect from http to https
Nginx you need to create two server section in the configuration file, one for http (port 80), one for https (port 443).
For the new domain conf. file nginx
Section server, to open at http (port 80) and forwarding settings:
server {
listen IP server: 80;
server_name www.domain.com;
rewrite ^ https: //www.domain.com$request_uri? permanent;
}
Section server, to open at https (port 443), where the main domain settings.
server {
listen IP server: 443;
server_name www.domain.com;
.....
}
For existing domain Conf. File nginx
If you make changes to an existing section of the conf. File nginx do this: From the main section of the domain, remove the string of the form
listen IP server: 80;
And create a new server section like this:
server {
listen IP server: 80;
server_name www.domain.com;
rewrite ^ https: //www.domain.com$request_uri? permanent;
}
After making changes to the configuration file Nginx, for entry into force of these changes, you need to restart it like this:
service nginx restart
The trick is that I can not do it. :)
My ngnix.conf file:
user www-data;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
# multi_accept on;
}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
keepalive_requests 400;
reset_timedout_connection on;
tcp_nodelay on;
server_tokens off;
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:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
open_file_cache max=200000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
client_max_body_size 8m;
client_body_buffer_size 4m;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_buffer_size 64k;
proxy_buffers 8 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 10m;
gzip on;
gzip_comp_level 8;
gzip_vary on;
gzip_static off;
gzip_types text/css text/plain application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;
gzip_min_length 1024;
gzip_disable "msie6";
gzip_proxied any;
include /etc/nginx/conf.d/default_server.conf;
server_names_hash_bucket_size 128;
log_format isp '$bytes_sent $request_length';
include /usr/local/ispmgr/etc/nginx.domain;
server {
server_name szh.kz www.szh.kz;
listen 185.22.232.116;
listen 185.22.232.116:443 ssl;
disable_symlinks if_not_owner from=$root_path/$subdomain;
set $root_path /var/www/szh/data/www/szh.kz;
set $subdomain "";
location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
access_log off;
access_log /var/www/nginx-logs/szh isp;
expires 30d;
root $root_path/$subdomain;
error_page 404 = @fallback;
}
location / {
proxy_pass http://185.22.232.116:81;
proxy_redirect http://185.22.232.116:81/ /;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
location @fallback {
proxy_pass http://185.22.232.116:81;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
}
include /usr/local/ispmgr/etc/nginx.inc;
if ($host ~* ^((.*).szh.kz)$) {
set $subdomain ../$1;
}
index index.php;
ssl_certificate /var/www/httpd-cert/szh/szh.kz.chained.crt;
ssl_certificate_key /var/www/httpd-cert/szh/szh.kz.key;
}
}