Last active
July 23, 2020 13:27
-
-
Save rajeshisnepali/2113ec72463a4ee4a1976f16979808c0 to your computer and use it in GitHub Desktop.
Redirect URL to https:// with non-www.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
server_name domain.com www.domain.com; | |
return 301 https://domain.com$request_uri; | |
} | |
server { | |
listen 443 ssl; | |
server_name www.domain.com; | |
return 301 https://domain.com$request_uri; | |
#ssl_certificate /etc/ssl/sites/domain.com.pem; | |
#ssl_certificate_key /etc/ssl/sites/domain.com.key; | |
} | |
server { | |
listen 443 ssl http2; | |
server_name domain.com; | |
root /srv/site/domain.com/public; | |
index index.php index.html index.htm; | |
#auth_basic "Administrator’s Area"; | |
#auth_basic_user_file /etc/nginx/.htpasswd; | |
# Security Headers | |
#add_header X-Frame-Options "SAMEORIGIN"; | |
#add_header X-XSS-Protection "1; mode=block"; | |
#add_header X-Content-Type-Options "nosniff"; | |
#add_header Referrer-Policy "strict-origin-when-cross-origin"; | |
#add_header Strict-Transport-Security "max-age=63072000"; | |
#add_header X-Permitted-Cross-Domain-Policies "master-only"; | |
location / { | |
try_files $uri $uri/ /index.php?$query_string; | |
} | |
location ~ \.php$ { | |
include snippets/fastcgi-php.conf; | |
fastcgi_pass unix:/run/php/php7.4-fpm.sock; | |
} | |
location ~ /\.ht { | |
deny all; | |
} | |
location = /favicon.ico { access_log off; log_not_found off; } | |
location = /robots.txt { access_log off; log_not_found off; } | |
location ~* .(ico|css|js|gif|jpeg|jpg|png|woff|ttf|otf|svg|woff2|eot|webp)$ { | |
expires 365d; | |
add_header Cache-Control "public, max-age=31536000"; | |
} | |
ssl_certificate /etc/ssl/sites/domain.com.pem; | |
ssl_certificate_key /etc/ssl/sites/domain.com.key; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment