“Nginx”的版本间的差异
		
		
		
		
		
		跳到导航
		跳到搜索
		
				
		
		
	
Jihongchang(讨论 | 贡献)  (→典型配置)  | 
				Jihongchang(讨论 | 贡献)   | 
				||
| 第62行: | 第62行: | ||
</syntaxhighlight>  | </syntaxhighlight>  | ||
| − | ===   | + | |
| + | |||
| + | |||
| + | |||
| + | === 配置请求转发 ===  | ||
<syntaxhighlight lang="console">  | <syntaxhighlight lang="console">  | ||
http {  | http {  | ||
| 第79行: | 第83行: | ||
这三个请求头的目的是告诉服务端当前请求的来源  | 这三个请求头的目的是告诉服务端当前请求的来源  | ||
| − | |||
=== 进程 ID 文件 ===  | === 进程 ID 文件 ===  | ||
/run/nginx.pid  | /run/nginx.pid  | ||
| − | |||
2023年2月10日 (五) 06:32的最新版本
目录结构
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:~ $