Any web developer may face a situation, at times, when both - HTTP and HTTPS - protocols have to be used to increase the protection level of the whole site or of its selected pages.
To implement the above, you have to fix the server settings, and in terms of this article we deal with the instances of Nginx and Apache severs configuration. The standard settings configuration procedure having done, one proceeds to configuring the host files, so as HTTP and HTTPS protocol usage location could be indicated (by default, they are located in /etc/nginx/sites-availabe/ folder). SSL key and the certificates will come handy, too, and they can either be purchased or generated on your own.
Terminal commands for the key and certificates generation are as follows:
openssl genrsa -des3 -outexamplekey 1024
openssl req -new -key xample.key -out.crt
In Common name you should input domain for which you generate keys.
Here is an example of “drupal7” host configuration done with mixed protocol http + https on the Nginx server (with the relevant file path: /etc/nginx/sites-available/drupal7):
server { ## HTTP protocol port. listen *:80; ## HTTPS protocol port. listen *:443 ssl; server_name example.com www.example.com; ## Server certificate and key. ssl_certificate /etc/nginx/ssl/example.crt; ssl_certificate_key /etc/nginx/ssl/example.key; root /var/www/example.com/htdocs; index index.html index.htm index.php index.cgi index.pl index.xhtml; error_log /var/log/nginx/drupal.error.log; access_log /var/log/nginx/drupal.access.log combined; server_tokens off; client_max_body_size 15M; # host_without_www if ($host ~* www\.(.*)) { set $host_without_www $1; rewrite ^(.*)$ http://$host_without_www$1 permanent; } ## Disable .htaccess and other hidden files location ~ /\. { deny all; access_log off; log_not_found off; } location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location ~* ^(?:.+\.(?:htaccess|make|txt|engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(?:\.php)?|xtmpl)|code-style\.pl|/Entries.*|/Repository|/Root|/Tag|/Template)$ { rewrite ^/(.*)$ /index.php?q=$1 last; } ## Factcgi configuration location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_ignore_client_abort off; fastcgi_connect_timeout 60; fastcgi_read_timeout 240; fastcgi_buffer_size 16M; fastcgi_buffers 4 32M; fastcgi_busy_buffers_size 64M; fastcgi_temp_file_write_size 64M; } ## Serve static files directly location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico)$ { access_log off; expires max; } ## Imagecache needs to have php read any files that it's planning to manipulate location ^~ /files/imagecache/ { index index.php; } ## Assume a clean URL is requested, and rewrite to index.php if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?q=$1 last; break; } location ^~ /files/ { allow all; log_not_found off; access_log off; } location ^~ /sites/default/files/ { allow all; log_not_found off; access_log off; } }