Nginx基础使用
命令
1. 启动:start nginx
2. 重启: nginx.exe -s reload
3. 关闭:nginx.exe -s stop
4. 杀进程(先查后杀)
方法一:- 先查:ps -ef|grep nginx
- 后杀:kill -HUP 端口号
- 图片说明:![例子](https://img.php.cn/upload/image/228/561/921/1559817616881161.png)
方法二:- taskkill /f /im nginx.exe : 强行关闭所有的Nginx进程
![image](https://img2023.cnblogs.com/blog/1401061/202302/1401061-20230224160220237-578765068.png)- 参考资料
[启动、重启](https://www.php.cn/nginx/421972.html)
介绍
配置
- 配置静态资源
location /pages/ {
alias D:/tools/nginx/2/html1/;
autoindex on;
}
- 配置证书
server {
# 默认配置端口是443
listen 8999 ssl;
server_name localhost;
#SSL证书
ssl_certificate F:/Application/cert/yjjh-ca.crt;
ssl_certificate_key F:/Application/cert/yjjh-ca.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
}
- 重定向
server {
# 方法一:通过状态码进行判断
error_page 497 301 https://$http_host$request_uri;
# 方法二:通过协议进行判断
if ( $scheme = http ){
return 301 https://$host$request_uri;
}
}
- 漏洞处理
server {
# 限制域名
if ($host !~* ^10.1.19.7|127.0.0.1|183.162.192.141|localhost$){
return 403;
}
}
常见的状态码
ngx_string(ngx_http_error_494_page), /* 494, request header too large /
ngx_string(ngx_http_error_495_page), / 495, https certificate error /
ngx_string(ngx_http_error_496_page), / 496, https no certificate /
ngx_string(ngx_http_error_497_page), / 497, http to https /
ngx_string(ngx_http_error_404_page), / 498, canceled /
ngx_null_string, / 499, client has closed connection */
补充: Nginx常见状态码
内置常用变量
- $host: 获取域名
- $scheme :获取协议
补充:nginx 内置变量大全