记录简单的 nginx 配置
快速操作
# 查看 Nginx 配置文件路径, 并检查格式是否正确
nginx -t
# -> nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
# -> nginx: configuration file /etc/nginx/nginx.conf test is successful
# 修改配置文件后重启生效
nginx -s reload
简单配置文件举例
example.com/ 代理到静态文件 example.com/api 代理到 8000 端口
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/nginx/crt/example.cer;
ssl_certificate_key /etc/nginx/crt/example.key;
location / {
root /data/code;
index index.html;
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://127.0.0.1:5000;
}
}
}