實用的 Nginx 配置片段
一組實用的 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.
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!