nginx - nginx 在使用 proxy_pass 功能时返回 404 结果
问题描述
我的配置文件@/etc/nginx/conf.d/:
server{
listen 443 ssl http2;
server_name api.opera.test.com;
client_max_body_size 1G;
ssl on;
ssl_certificate /etc/nginx/cert/_.test.com.crt;
ssl_certificate_key /etc/nginx/cert/_.test.com.key;
ssl_session_timeout 5m;
location / {
if ($request_method ~* "(GET|POST)") {
add_header "Access-Control-Allow-Origin" *;
}
if ($request_method = OPTIONS ) {
add_header "Access-Control-Allow-Origin" *;
add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, HEAD";
add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
return 200;
}
proxy_pass http://127.0.0.1:6666/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Fowarded-For $proxy_add_x_forwarded_for;
proxy_cache_valid 200 3d;
proxy_ssl_server_name on;
proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
但是当我卷曲我代理的主机时,它返回:
[root@develop conf.d]# systemctl restart nginx
[root@develop conf.d]# curl -k http://api.opera.test.com:6666
hello world!
[root@develop conf.d]# curl -k https://api.opera.test.com
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.14.0</center>
</body>
</html>
我尝试使用 proxy_pass http://127.0.0.1:6666;而不是 proxy_pass http://127.0.0.1:6666/;不幸的是,对我不起作用。
解决方案
此命令帮助我解决了问题:setsebool -P httpd_can_network_connect 1
推荐阅读
- php - Composer 安装出错 - 无法扫描 /vendor 目录中库依赖项中的类
- xaml - 定义 Shell.TitleView,同时在 shell 中保留选项卡的标题文本,但似乎以不同的字体显示
- java - 如何从 Android 本地存储中获取媒体文件(图像、视频、音频)?
- angular - 如何在 mat-menu 中设置空消息的样式?
- c# - 如何从 Oracle 数据库获取定期更新到客户端(轮询除外)?
- push-notification - 如何正确处理注册用户的登录/注销而不向注销用户发送通知?
- c# - C# MongoDB - 从数据库中读取一条记录并将其写入流
- c# - 一对一的EF关系
- angular - angular - 如何将组件内声明的变量的值获取到服务文件?
- java - 为什么用户在 Java 中总是返回 true?