nginx配置文件的编写
时间: 2023-12-20 12:32:00 浏览: 67
以下是关于nginx配置文件编写的示例:
1. 配置监听端口和服务器名称
```nginx
server {
listen 80;
server_name example.com;
}
```
2. 配置反向代理
```nginx
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:3000;
}
}
```
3. 配置负载均衡
```nginx
upstream backend {
server backend1.example.com weight=5;
server backend2.example.com;
}
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://backend;
}
}
```
4. 配置SSL
```nginx
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/nginx/ssl/example.com.crt;
ssl_certificate_key /etc/nginx/ssl/example.com.key;
location / {
proxy_pass http://localhost:3000;
}
}
```
阅读全文