实用的 Nginx 配置片段
jopen
10年前
一组实用的 Nginx 片段。
内容目录
- The Nginx Command
- Rewrite and Redirection </li>
- Performance
- Contents Caching
- Gzip Compression
- Open File Cache
- SSL Cache
- Upstream Keepalive </ul> </li>
- Monitoring
- Security
- Enable Basic Authentication
- Only Allow Access From Localhost </ul> </li>
- Miscellaneous
- Sub-Request Upon Completion
- Enable Cross Origin Resource Sharing </ul> </li>
- Links </ul>
- Get current Nginx version and its configured compiling parameters:nginx -V
- Test the current Nginx configuration file and / or check its location:nginx -t
- Reload the configuration without restarting Nginx:nginx -s reload
The Nginx Command
Thenginxcommand can be used to perform some useful actions when Nginx is running.
Rewrite and Redirection
Force www
The right way is to define a separated server for the naked domain and redirect it.
server { listen 80; server_name example.org; return 301 $scheme://www.example.org$request_uri; } server { listen 80; server_name www.example.org; ... }
https://github.com/lebinh/nginx-confNote that this also works with HTTPS site.