估计大家都没有踩过的nginx坑

简介: 记录一次NGINX踩坑

直接上nginx配置,大家看看有没有问题呢

root用户运行

test.conf 

server{
listen443 ssl;
server_nameauth-api.dataflux.cn;
ssl_certificate      /tmp/server.crt;
ssl_certificate_key  /tmp/server.key;
location / {
root   /root/nginx/dist/;
indexindex.html index.htm;
        }
location /server_status {
stub_status on;
access_log off;
       }
}


重启nginx

[root@izbp152ke14timzud0du15z conf.d]# service nginx restartRedirecting to /bin/systemctl restart nginx.serviceJob for nginx.service failedbecause thecontrol processexited witherror code. See "systemctl status nginx.service"and "journalctl -xe"for details.


查看日志

journalctl -xe-u nginx

image.png


说是 /tmp/server.crt 文件不能加载

但是证书文件都是存在的

[root@izbp152ke14timzud0du15z conf.d]# ls -l /tmp/server.crt  /tmp/server.key-rw-r--r--1 root root 1399 Nov  621:56 /tmp/server.crt
-rw-r--r--1 root root 1679 Nov  621:56 /tmp/server.key

验证下nginx配置文件是不是有问题,那么测试一下,居然报错了

[root@izbp152ke14timzud0du15z conf.d]# nginx -tc /etc/nginx/conf.d/test.confnginx: [emerg] "server" directive is not allowed here in /etc/nginx/conf.d/test.conf:1
nginx: configuration file /etc/nginx/conf.d/test.conf test failed

但是我实在想不出有什么错误,网上查找了下,测试配置文件,不能这样测试,要测试 nginx.conf 文件才算是完整的测试

[root@izbp152ke14timzud0du15z conf.d]# nginx -tc /etc/nginx/nginx.confnginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

目前语法没有错误,就是NGINX 报错起不来,提示 /tmp/server.crt 文件加载不了,于是我把证书相关文件拷贝到其它目录去了(想到这一步花了挺长时间,流泪)

server{
listen443 ssl;
server_nameauth-api.dataflux.cn;
ssl_certificate      /root/dac/server.crt;
ssl_certificate_key  /root/dac/server.key;
location / {
root   /root/nginx/dist/;
indexindex.html index.htm;
        }
location /server_status {
stub_status on;
access_log off;
       }
}


再次测试并重启nginx,竟然成功启动了,难道是 /tmp 目录没有权限,不可能啊,是root啊,是因为这是临时目录吗,我竟然踩了这样一个坑

[root@izbp152ke14timzud0du15z conf.d]# nginx -tc /etc/nginx/nginx.confnginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@izbp152ke14timzud0du15z conf.d]# service nginx restartRedirecting to /bin/systemctl restart nginx.service

验证访问

[root@izbp152ke14timzud0du15z conf.d]# curl -w "%{http_code}\n" -o /dev/null https://172.16.5.9 -k  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
1004628100462800440250--:--:-- --:--:-- --:--:-- 44500200
目录
相关文章
|
3月前
|
缓存 应用服务中间件 网络安全
Nginx中配置HTTP2协议的方法
Nginx中配置HTTP2协议的方法
227 7
|
4月前
|
应用服务中间件 BI nginx
Nginx的location配置详解
【10月更文挑战第16天】Nginx的location配置详解
|
4月前
|
缓存 负载均衡 安全
Nginx常用基本配置总结:从入门到实战的全方位指南
Nginx常用基本配置总结:从入门到实战的全方位指南
502 0
|
21天前
|
存储 应用服务中间件 Linux
nginx配置证书和私钥进行SSL通信验证
nginx配置证书和私钥进行SSL通信验证
56 4
|
3月前
|
负载均衡 监控 应用服务中间件
配置Nginx反向代理时如何指定后端服务器的权重?
配置Nginx反向代理时如何指定后端服务器的权重?
220 61
|
3月前
|
安全 应用服务中间件 网络安全
如何测试Nginx反向代理实现SSL加密访问的配置是否正确?
如何测试Nginx反向代理实现SSL加密访问的配置是否正确?
227 60
|
3月前
|
安全 应用服务中间件 网络安全
配置Nginx反向代理实现SSL加密访问的步骤是什么?
我们可以成功地配置 Nginx 反向代理实现 SSL 加密访问,为用户提供更安全、可靠的网络服务。同时,在实际应用中,还需要根据具体情况进行进一步的优化和调整,以满足不同的需求。SSL 加密是网络安全的重要保障,合理配置和维护是确保系统安全稳定运行的关键。
301 60
|
2月前
|
存储 应用服务中间件 nginx
nginx反向代理bucket目录配置
该配置实现通过Nginx代理访问阿里云OSS存储桶中的图片资源。当用户访问代理域名下的图片URL(如 `http://代理域名/123.png`)时,Nginx会将请求转发到指定的OSS存储桶地址,并重写路径为 `/prod/files/2024/12/12/123.png`。
100 5
|
3月前
|
缓存 负载均衡 算法
如何配置Nginx反向代理以实现负载均衡?
如何配置Nginx反向代理以实现负载均衡?
|
3月前
|
存储 负载均衡 中间件
Nginx反向代理配置详解,图文全面总结,建议收藏
Nginx 是大型架构必备中间件,也是大厂喜欢考察的内容,必知必会。本篇全面详解 Nginx 反向代理及配置,建议收藏。
Nginx反向代理配置详解,图文全面总结,建议收藏