Creating Nginx SSL Subdomains
Creating Nginx SSL Subdomains is easy but this took me a bit of time to get right. Once I figured out the process most everything else with Nginx became allot easier…First we want to create our subdomain. I am using ISPconfig to do this but any control panel that works solely with Nginx will do the trick. This will not apply to those using Nginx as a frontend for Apache on cPanel server. This is pure Nginx server no Apache.
The following makes all requests go to https by using the redirect in the http (port 80) block. The following is a standard server block, I have left out any custom directives for easier reading.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
server { listen IPaddress:80; server_name sub.domain.com; #################### SSL Only Please rewrite ^ https://$server_name$request_uri? permanent; } server { listen 443; server_name sub.domain.com; error_log /var/log/ispconfig/httpd/domain.com/sub_error.log; access_log /var/log/ispconfig/httpd/domain.com/sub_access.log combined; ################### Sub Domain Root root /var/www/domain.com/web/sub; ################### SSL Directives ssl on; ssl_certificate /var/www/domain.com/ssl/sub.domain.com.pem; ssl_certificate_key /var/www/domain.com/ssl/sub.domain.com.key; ssl_session_timeout 5m; ssl_protocols SSLv2 SSLv3 TLSv1; ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; ssl_prefer_server_ciphers on; #################### Page Extension Directives index index.php index.html index.htm index.cgi index.pl index.xhtml; #################### The Error Pages error_page 400 /error/400.html; error_page 401 /error/401.html; error_page 403 /error/403.html; error_page 404 /error/404.html; error_page 405 /error/405.html; error_page 500 /error/500.html; error_page 502 /error/502.html; error_page 503 /error/503.html; #################### Standard Directives ## 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 /stats { index index.html index.php; auth_basic "Members Only"; auth_basic_user_file /var/www/clients/client1/web1/.htpasswd_stats; } ######################### PHP-FPM Fast CGI Directives location ~ \.php$ { try_files $uri =404; include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9010; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS on; fastcgi_buffer_size 128k; fastcgi_buffers 256 4k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; } ################### Server Your Static ZFiles # serve static files directly location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$ { access_log off; } } |
After you are dont configuring, save your file and restart Nginx
|
1 |
# /etc/init.d/nginx restart |
So Creating Nginx SSL Subdomains isnt that difficult and you can use the same process to secure your domains, subdomains, and directories.
Reference: Nginx HttpSslModule
More code, copy code ability, full support, and your comments here