跳到主要内容

Nginx 配置示例

· 阅读需 1 分钟
素明诚
Full stack development
http {
# 基础配置
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;

# 日志配置
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

# 服务器配置
server {
listen 80; # 监听端口
server_name localhost; # 服务器名

# 对 /http 请求的处理
location /http {
# URL 重写,移除 '/http'
rewrite ^/http/(.*) /$1 break;

# 代理设置
proxy_pass http://localhost:3335;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;

# 设置代理的头部信息
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

# 默认处理
location / {
root html;
index index.html index.htm;
}

# 错误页面配置
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}