“Nginx”的版本间的差异
		
		
		
		
		
		跳到导航
		跳到搜索
		
				
		
		
	
Jihongchang(讨论 | 贡献)  | 
				Jihongchang(讨论 | 贡献)   | 
				||
| (未显示同一用户的8个中间版本) | |||
| 第1行: | 第1行: | ||
| + | https://www.nginx.com/  | ||
| + | |||
| + | === 目录结构 ===  | ||
| + | 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  | /etc/nginx/nginx.conf  | ||
| + | === 典型配置 ===  | ||
| + | <syntaxhighlight lang="console">  | ||
| + | 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;  | ||
| + |         }  | ||
| + |     }  | ||
| + | }  | ||
| + | |||
| + | </syntaxhighlight>  | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | === 配置请求转发 ===  | ||
| + | <syntaxhighlight lang="console">  | ||
| + | http {  | ||
| + |     server {  | ||
| + |         listen 80;  | ||
| + | |||
| + |         location / {  | ||
| + |             proxy_pass http://localhost:8080;  | ||
| + |             proxy_set_header Host $host;  | ||
| + |             proxy_set_header X-Real-IP $remote_addr;  | ||
| + |         }  | ||
| + |     }  | ||
| + | }  | ||
| − | 校验配置文件<syntaxhighlight lang="shell-session">  | + | </syntaxhighlight>需要注意的是,在这段配置中使用了 proxy_set_header 设置的三个请求头,分别是 Host、X-Real-IP 和 X-Forwarded-For。  | 
| + | |||
| + | 这三个请求头的目的是告诉服务端当前请求的来源  | ||
| + | |||
| + | |||
| + | === 进程 ID 文件 ===  | ||
| + | /run/nginx.pid  | ||
| + | |||
| + | |||
| + | === 校验配置文件 ===  | ||
| + | <syntaxhighlight lang="shell-session">  | ||
pi@raspberrypi:~ $ sudo nginx -t  | pi@raspberrypi:~ $ sudo nginx -t  | ||
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok  | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok  | ||
nginx: configuration file /etc/nginx/nginx.conf test is successful  | nginx: configuration file /etc/nginx/nginx.conf test is successful  | ||
| + | pi@raspberrypi:~ $  | ||
| + | </syntaxhighlight>  | ||
| + | |||
| + | |||
| + | |||
| + | === 重启 ===  | ||
| + | <syntaxhighlight lang="shell-session">  | ||
| + | pi@raspberrypi:~ $ sudo nginx -s reload  | ||
pi@raspberrypi:~ $  | pi@raspberrypi:~ $  | ||
</syntaxhighlight>  | </syntaxhighlight>  | ||
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:~ $