Nginx 是一个高性能的开源 Web 服务器和反向代理服务器。它可以用于提供静态内容、负载均衡、反向代理、缓存以及许多其他功能。本文将介绍如何配置 Nginx 以满足不同的需求。
- 安装 Nginx
首先,确保已经安装了适合你操作系统的 Nginx 版本。可以通过包管理器进行安装,例如在 Ubuntu 上使用以下命令:
sudo apt update
sudo apt install nginx
- 配置 Nginx
Nginx 的配置文件位于 /etc/nginx/nginx.conf
。打开该文件,并按照下面的示例进行配置。
worker_processes auto;
error_log /var/log/nginx/error.log;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name example.com;
location / {
root /var/ww