Nginx 502错误两种解决方案介绍

开发 前端
Nginx 502错误是我们最常见的一个问题,我们需要不断的学习有关知识。下面我们就来详细的学习有关的问题如何才能解决。

我们在使用Nginx的时候有不少问题出现,首先我们就来解决下Nginx 502错误的问题。定义Nginx 404 502错误提示页面,直接配置Nginx 502错误,找了很多资料,最终没能实现。下面用另一个方法实现.

方法一:在Nginx.conf配置文件里加上以下红色代码

  1. erver   
  2. {   
  3. listen 80;   
  4. server_name www.tt.com;   
  5. location / {   
  6. proxy_pass http://week;   
  7. proxy_set_header Host $host;   
  8. proxy_set_header X-Real-IP $remote_addr;   
  9. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   
  10. if (!-f $request_filename) {   
  11. proxy_pass http://127.0.0.1:8888;   
  12. }   

17.0.0.1:8888配置如下

  1. erver   
  2. {   
  3. listen 8888;   
  4. server_name www.tt.com;   
  5. location / {   
  6. root /root;   
  7. index index.html;   
  8. error_page 500 502 404 /404.html;   
  9. }   

需要维护的时候,只需要重启Nginx服务。

  1. kill -HUP 'cat logs/nginx.pid' 

方法二:单***建一个testnginx.conf文件

  1. #user nobody;   
  2. worker_processes 1;   
  3. pid logs/nginx.pid;   
  4. events {   
  5. use epoll;   
  6. worker_connections 50000;   
  7. }   
  8. http {   
  9. include mime.types;   
  10. default_type application/octet-stream;   
  11. sendfile on;   
  12. server   
  13. {   
  14. listen 80;   
  15. server_name www.tt.com;   
  16. location / {   
  17. root /root;   
  18. index index.html;   
  19. error_page 500 502 404 /404.html;   
  20. }   
  21. }   
  22. }  

维护时只需把Nginx 502错误停止,从新启用新的配置文件

  1. killall -9 nginx   
  2. nginx -c ../conf/testnginx.conf 

以上就是对Nginx 502错误的详细介绍希望大家有所帮助。

【编辑推荐】

  1. nginx配置虚拟主机具体的代码配置
  2. nginx默认虚拟主机如何在server中添加
  3. nginx负载均衡如何进行配置
  4. nginx配置文件经典教程分析
  5. nginx配置文件实现AWStats静态页面
责任编辑:张浩 来源: 互联网
相关推荐

2010-09-30 14:35:36

JS浮点溢出

2009-11-16 09:45:51

PHP上传文件大小

2009-11-16 13:46:28

PHP上传文件大小限制

2010-06-07 17:41:42

Sendmail 配置

2010-10-09 16:04:22

J2ME代码优化

2010-03-29 17:46:39

Nginx asp

2010-05-19 15:42:08

2010-03-24 18:19:42

Nginx php

2009-10-27 09:49:38

无线接入技术

2009-11-11 16:36:19

路由协议介绍

2019-05-15 10:59:50

开发者技能工具

2009-12-07 13:42:24

WCF框架

2009-12-29 16:07:19

ADO类型

2009-10-15 10:29:03

布线系统解决方案

2010-11-17 09:48:07

Nginx 502错误

2009-10-28 10:34:12

2010-05-26 18:20:59

SVN库

2018-06-04 09:43:53

分层存储Linux

2010-01-06 16:53:57

JS两种语法

2010-02-01 10:22:51

C++数据指针
点赞
收藏

51CTO技术栈公众号