Nginx 是一个高性能的 HTTP 和反向代理服务器,以及一个 IMAP/POP3/SMTP 代理服务器。它常用于网站服务器,也可以作为反向代理服务器来提高网站的性能和安全性。
安装 Nginx
Linux 系统安装
在 Linux 系统上安装 Nginx,可以使用以下命令:
sudo apt-get update
sudo apt-get install nginx
Windows 系统安装
在 Windows 系统上安装 Nginx,可以从 Nginx 官网 下载安装包。
配置 Nginx
Nginx 的配置文件位于 /etc/nginx/nginx.conf
。以下是一个简单的配置示例:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
Nginx 常用命令
- 启动 Nginx:
sudo systemctl start nginx
- 停止 Nginx:
sudo systemctl stop nginx
- 重启 Nginx:
sudo systemctl restart nginx
- 查看Nginx状态:
sudo systemctl status nginx
Nginx Logo