首页 > 系统相关 >nginx常见问题

nginx常见问题

时间:2022-11-22 11:38:05浏览次数:47  
标签:常见问题 http ssl header nginx set proxy


前言

本文记载一些nginx常见问题

1. connect() fail

转发的服务挂了,确保主服务正常运行。可以使用 lsof -i:端口号 确定被转接的服务的状态

2. nginx 50X 的错误日志去哪看,配置的默认路径去哪配

日志在​​/var/log/nginx/​​​ 配置路径在 ​​/etc/nginx/conf.d​​, 配置文件以​​.ini​​ 结尾。

3. nginx 怎么对服务热更新,热重启

使用负载均衡,对业务服务开启最少两个。

upstream srv_name {
server localhost:8112 weight=3;
server localhost:10112 weight=1;
}

热更新时,只要分别对两个均衡的服务更新,即可。这里有两个nginx的特点:

  • 均衡的某个服务挂了,nginx自动屏蔽该服务,使用其他均衡的服务节点。
  • 已经挂起的服务重新跑起,nginx会自动接受新的服务,并按照权重回到正常均衡场景。

4. nginx修改配置后平滑重载热更

nginx -t
nginx -s reload

5. nginx如何配置证书ssl

如下图第六,七行。通过云服务商申请https证书,或者获取免费的证书,所有的证书都支持tomcat和nginx,nginx的证书格式一般是​​*.crt​​​和​​*.key​​。将证书放置在对应的位置,重置nginx即可。重置命令见#4

server {
listen 443 ssl;
server_name xyx.zonst.com;
root /usr/share/nginx/html;

ssl_certificate "/etc/nginx/certs/xyx.crt";
ssl_certificate_key "/etc/nginx/certs/xyx.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;

# request header

proxy_set_header Host $http_host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
}

location /api/ {
proxy_pass http://xyx_srv_http;
}
}

6. nginx如何配置tcp

stream {
upstream backend {
server 10.0.0.5:2000;
}
server {
listen 2000;
proxy_connect_timeout 8s;
proxy_timeout 24h;
proxy_pass backend;
}
}

7. nginx如何配置websocket

location /{
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}

8 400 Bad Request: The plain HTTP request was sent to HTTPS port

尝试将80的http转发到443时,发生了这个错误,解决方法是
在80的proxy_pass里,将http改成https

跨域

以下4个可以解决跨域

proxy_set_header   Host             $http_host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

9. nginx如何查看实时/归档异常接口

> tail -n 200 -f xyx.zzect.log.access | awk '{print $9  $7}' | grep '^[4-5][0-9][0-9]'

403/api/xxx/
403/api/xxx/
403/api/user-mail-box/external/read-status-by-type/
403/api/xxx/


标签:常见问题,http,ssl,header,nginx,set,proxy
From: https://blog.51cto.com/u_11553781/5877243

相关文章

  • nginx做直播
    最近在做直播项目,查阅了一下相关资料然后成功搭建服务,在这里整理记录下实现过程以及踩过的坑。一、直播协议简介:首先,在搭建服务之前先了解下目前主流的几个直播协议:1、RTMP:......
  • 常见问题解决方案
    1.Failedtofindthek3s-selinuxpolicy检查master机器上是否已经安装了不同版本的k3s-selinux或者selinux-policy工具包,建议将机器上相关包全部卸载以后重新执行安装。......
  • K8S Pod Sidecar 应用场景之一-加入 NGINX Sidecar 做反代和 web 服务器
    KubernetesPodSidecar简介Sidecar是一个独立的容器,与Kubernetespod中的应用容器一起运行,是一种辅助性的应用。Sidecar的常见辅助性功能有这么几种:服务网格(s......
  • Nginx配置多个域名以及一个域名多个端口
    转:Nginx配置多个域名以及一个域名多个端口 域名后边带着端口如何设置? ......
  • windows服务器Nginx一键安装部署
    原文链接:https://www.cnblogs.com/xiaoXuZhi/p/nginx.html作为一名专业搬砖工,Nginx是我们绕不开的砖头,最近连续部署了几个服务器,Ctrl a+Ctrlv在飞来飞去,总是会遇到......
  • 用nginx构建高效不限速的个人网盘
    1、源码编译安装nginx并部署私人网盘系统1.1项目环境说明操作系统:Centos7.9服务器IP:涉及软件:nginx、网盘程序、ssl证书(需要自己去阿里云免费申请)nginx官方网站:http://......
  • centos安装nginx的几种方式与适用场景分析
    一、在线安装前置条件:服务器能够联通外网。使用linux默认源安装(推荐)适用场景:只是使用nginx做一些简单的反向代理,对nginx没有太深度的应用,对版本没有要求。优点:简单......
  • Nginx 代理 jira 和 confluence
    jira和confluence想部署到同一台机器上。都使用80端口访问。使用nginx代理吧。直接使用proxy_passhttp://127.0.0.1:8080jira的首页小插件不太好使。发现使用tr......
  • 第二节 nginx整体结构、进程模型
    一、nginx的整体结构1、master进程和worker进程概览(父子关系)启动nginx进程,用ps-ef|grepnginx打印出进程来,可以看到一个master进程,一个worker进程第一列:UID,进程所属......
  • 1.nginx快速使用(基于docker)
    根据B站视频做的笔记,链接如下:https://www.bilibili.com/video/BV1W54y1z7GM?p=3这篇博客是为了方便快速使用nginx的人上手入门,深入探究的笔记,以后再添加文章目录ng......