nginx正确的配置文件
时间: 2023-07-08 17:52:03 浏览: 55
Nginx 的正确配置文件因具体情况而异,根据您的需求和服务器环境不同,配置文件也会有所不同。以下是一个简单的 Nginx 配置示例,供您参考:
```nginx
# 基本配置
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
# 事件模块
events {
worker_connections 1024;
}
# HTTP 配置
http {
# MIME 类型
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;
# Gzip 压缩
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
# 服务器配置
server {
listen 80;
server_name example.com;
# 静态文件目录
location /static/ {
alias /var/www/example.com/static/;
}
# 动态请求
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
```
这个配置文件包含了 Nginx 的基本配置、事件模块配置、HTTP 配置以及一个简单的服务器配置,用来处理静态文件和动态请求。您可以根据自己的需求进行相应的修改和调整。