![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpVYdF2bHeU-hqhaNzPW1uhJncW5K0PWBvPjqx-6qs_hkbRyXAhTjwTGcflcauJZf_uamrgYt3vgvK2OA9ps17FWUC6JCOygHYX0_YONiXktbSI5PLdyndsatsoHDm24tCE1yPj0gv9CLS/s640/rect5987.png)
Nginx configuration code snippets.
Basic commands![](https://goo.gl/njhShQ)
nginx -t - test configuration file. nginx -s reload - reload Nginx configuration file, without webserver restart.
Force Trailing Slash![](https://goo.gl/njhShQ)
Add a slash "/" at end of every URL.
rewrite ^([^.\?]*[^/])$ $1/ permanent;
Redirect to page![](https://goo.gl/njhShQ)
server {
location = /oldpage.html {
return 301 http://example.org/newpage.html;
}
}
Redirect to domain![](https://goo.gl/njhShQ)
server {
server_name old-site.com
return 301 $scheme://new-site.com$request_uri;
}
Redirect to specific URL![](https://goo.gl/njhShQ)
location /old-site {
rewrite ^/old-site/(.*) http://example.org/new-site/$1 permanent;
}
Forbid browsers to cache content![](https://goo.gl/njhShQ)
location = /empty.gif {
empty_gif;
expires -1;
}
Gzip compression![](https://goo.gl/njhShQ)
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
gzip_types
text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
text/javascript application/javascript application/x-javascript
text/x-json application/json application/x-web-app-manifest+json
text/css text/plain text/x-component
font/opentype application/x-font-ttf application/vnd.ms-fontobject
image/x-icon;
gzip_disable "msie6";
SSL cache![](https://goo.gl/njhShQ)
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
Forbid Iframe![](https://goo.gl/njhShQ)
add_header X-Frame-Options SAMEORIGIN;
Forbid security scanners![](https://goo.gl/njhShQ)
if ( $http_user_agent ~* (nmap|nikto|wikto|sf|sqlmap|havij|appscan) ) {
return 403;
}
Accept 80 and 443 SSL![](https://goo.gl/njhShQ)
server {
listen 80;
listen 443 ssl; # This SSL switch is important!!!.
server_name servername;
0 comments :
Post a Comment
Comment: