Nginx
跳到导航
跳到搜索
目录结构
conf.d
fastcgi.conf
fastcgi_params
koi-utf
koi-win
logs
mime.types
modules-available
modules-enabled
nginx.conf
proxy_params
scgi_params
sites-available
sites-enabled
snippets
uwsgi_params
win-utf
配置文件
/etc/nginx/nginx.conf
典型配置
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name example.com;
location / {
root /var/www/example.com;
index index.html index.htm;
}
}
}
配置请求转发
http {
server {
listen 80;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
}
需要注意的是,在这段配置中使用了 proxy_set_header 设置的三个请求头,分别是 Host、X-Real-IP 和 X-Forwarded-For。
这三个请求头的目的是告诉服务端当前请求的来源
进程 ID 文件
/run/nginx.pid
校验配置文件
pi@raspberrypi:~ $ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
pi@raspberrypi:~ $
重启
pi@raspberrypi:~ $ sudo nginx -s reload
pi@raspberrypi:~ $