无法启动nginx,急急急!

无法启动nginx,急急急!,第1张

修改nginx配置文件,部署redmine

sudo vi /opt/nginx/conf/nginx.conf

在该配置文件中添加一个server 块,用于redmine服务。以下是添加的内容

# rails server

server {

listen 80

server_name redmine

root /opt/redmine/web/public  # <--- be sure to point to 'public'!

passenger_enabled on

}手上没截图,就文字表示了,按这个 *** 作就可以的。

Nginx ("engine x") 是一个高性能的HTTP和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。2011年6月1日,nginx 1.0.4发布。

Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度、新浪、网易、腾讯、 淘宝等。

这不是问题,nginx在安装完成后默认是这样的。你需要自己在nginx.conf文件中写你自己需要的server配置。我给你个nginx.conf配置文件参考,你可以根据下面的信息来进行修改:

user richmail richmail  

#worker_processes  4  

#worker_cpu_affinity 0001 0010 0100 1000  

worker_rlimit_nofile 65535  

pid        /home/richmail/nginx/logs/nginx.pid  

  

events {  

    use epoll  

    worker_connections 256   

}  

  

http {  

    include       mime.types  

    default_type  application/octet-stream  

    server_tokens off  

    server_names_hash_bucket_size 128  

    client_header_buffer_size 32k  

    large_client_header_buffers 4 32k  

    sendfile        on  

    tcp_nopush     on  

    keepalive_timeout  30  

    tcp_nodelay on  

    log_format acc  '$remote_addr - $remote_user [$time_local] "$request" '  

                      '$status $upstream_response_time $body_bytes_sent "$http_referer" "$sent_http_location"'  

                      '"$http_user_agent" "$http_x_forwarded_for"'  

    gzip on  

    gzip_comp_level 2  

    gzip_http_version   1.1  

    gzip_types      text/plain application/x-javascript text/css application/xml text/javascript  

    gzip_proxied        any  

    gzip_vary   on  

  

    proxy_cache_path /home/richmail/nginx/cache levels=1:2 keys_zone=tmp_cache:1024m inactive=20m max_size=1024m  

    #proxy_set_header X-Forwarded-Proto https  

    add_header X-Frame-Options SAMEORIGIN  

    #add_header Cache-Control no-store   

  

    server {  

        listen       80  

        server_name _  

        access_log  /home/richmail/logs/xx.nginx.log acc  

        error_log  /home/richmail/logs/xx.nginx.err  info  

        root /home/richmail/nginx/html  

        proxy_intercept_errors on  

        error_page   500 /error.html  

        error_page   404 /404.html  

user richmail richmail  

#worker_processes  4  

#worker_cpu_affinity 0001 0010 0100 1000  

worker_rlimit_nofile 65535  

pid        /home/richmail/nginx/logs/nginx.pid  

  

events {  

    use epoll  

    worker_connections 256   

}  

  

http {  

    include       mime.types  

    default_type  application/octet-stream  

    server_tokens off  

    server_names_hash_bucket_size 128  

    client_header_buffer_size 32k  

    large_client_header_buffers 4 32k  

    sendfile        on  

    tcp_nopush     on  

    keepalive_timeout  30  

    tcp_nodelay on  

    log_format acc  '$remote_addr - $remote_user [$time_local] "$request" '  

                      '$status $upstream_response_time $body_bytes_sent "$http_referer" "$sent_http_location"'  

                      '"$http_user_agent" "$http_x_forwarded_for"'  

    gzip on  

    gzip_comp_level 2  

    gzip_http_version   1.1  

    gzip_types      text/plain application/x-javascript text/css application/xml text/javascript  

    gzip_proxied        any  

    gzip_vary   on  

  

    proxy_cache_path /home/richmail/nginx/cache levels=1:2 keys_zone=tmp_cache:1024m inactive=20m max_size=1024m  

    #proxy_set_header X-Forwarded-Proto https  

    add_header X-Frame-Options SAMEORIGIN  

    #add_header Cache-Control no-store   

  

    server {  

        listen       80  

        server_name _  

        access_log  /home/richmail/logs/xx.nginx.log acc  

        error_log  /home/richmail/logs/xx.nginx.err  info  

        root /home/richmail/nginx/html  

        proxy_intercept_errors on  

        error_page   500 /error.html  

        error_page   404 /404.html  

        error_page   404 /404.html  

        }  

  

    server {  

        listen       80  

        server_name webnote.com 127.0.0.1 192.168.34.92  

        access_log  /home/richmail/logs/mail.nginx.log acc  

        error_log  /home/richmail/logs/mail.nginx.err  info  

        proxy_intercept_errors on  

        error_page   500 502 503 504 /error.html  

        error_page   404 /404.html  

        error_page   403 =404 /forbidden.gif  

        if ($request_method !~* GET|HEAD|POST) {  

                return 400  

        }  

        include conf.d/note.conf  

    }  

    server {  

        listen       443  

        server_name webnote.com 127.0.0.1 192.168.34.92  

        access_log  /home/richmail/logs/mailssl.nginx.log acc  

        error_log  /home/richmail/logs/mailssl.nginx.err  info  

        proxy_intercept_errors on  

        error_page   500 502 503 504 /error.html  

        error_page   404 /404.html  

        error_page   403 =404 /forbidden.gif  

        if ($request_method !~* GET|HEAD|POST) {  

                return 400  

        }  

        add_header Cache-Control no-store  

        add_header Pragma: no-cache  

        ssl on  

        ssl_certificate server.pem  

        ssl_certificate_key privkey.pem  

        include conf.d/note.conf  

        }  

}

nginx报错 502 no live upstreams while connecting to upstream

nginx 跟后端创建了大量的连接。没有使用http1.1长连接导致的(默认是http1.0短连接)。

解决方案:在upstream中添加keepalive配置

默认情况下 Nginx 访问后端都是用的短连接(HTTP1.0),一个请求来了,Nginx 新开一个端口和后端建立连接,请求结束连接回收。如果配置了http 1.1长连接,那么Nginx会以长连接保持后端的连接,如果并发请求超过了 keepalive 指定的最大连接数,Nginx 会启动新的连接来转发请求,新连接在请求完毕后关闭,而且新建立的连接是长连接。

nginx1.1.4版本开始支持长连接

同一网段不经过防火墙,不会对长连接状态进行干预;不同网段(生产上)一般都有防火墙,,会对连接状态进行重置

生产上防火墙连接要确认是长连接还是短连接,如果要开通长连接要有链接探测机制,释放无效链接,以免影响防火墙性能。

如果含有Tomcat的话也需要配置server.xml Connector

Nginx 与后端机器的通信效率更高,后端机器的负担更低。

netstat -n | grep TIME_WAIT

nginx配置了proxy_next_upstream属性,这个属性作用是如果发现请求返回的是后面的配置状态时就会转发到下一个upstream

测试发现,如果每个实例都返回500后,接下来的请求就会出现502,如果访问正常的api,又会恢复正常,说明nginx当发现upstream都为500的时候,就会临时disable所有upstream,也就是上面error.log上出现的“upstream server temporarily disabled”,后续请求就会有“no live upstreams”问题,但是出现502后,新请求会重新检测,当请求是200,就会恢复正常。

解决:问题原因找到了,解决办法也就简单了,这个500一般是服务器端的bug,一般请求都不会直接返回500,出现问题及时解决就好,另外这个使用这个属性时得注意,如果请求是后面枚举的状态时,nginx会直接转到另外一个upstream,所以会出现多个实例都接收到请求的情况,有些情况下是不允许的,所以使用的时候需要分析一下。

原文链接: https://blog.csdn.net/piaohai/article/details/102753168

下面还有一个参数影响重试次数,0表示不限制。:

Syntax: proxy_next_upstream_tries number

Default:proxy_next_upstream_tries 0

Context:http, server, location

原文链接: https://blog.csdn.net/christ1208/article/details/106949000/

HTTP只要能返回状态说明该节点还可以正常连接,所以nginx判断其还是存活状态除非添加了proxy_next_upstream指令设置对404、502、503、504、500和time out等错误转到备机处理,

nginx记录错误数量只记录timeout 、connect refuse、502、500、503、504这6种状态,timeout和connect refuse是永远被记录错误状态,而502、500、503、504只有在配置proxy_next_upstream参数之后nginx才会记录这4种HTTP错误到fails中;

https://blog.csdn.net/weixin_30621711/article/details/96625770

https://blog.csdn.net/my201110lc/article/details/108245658

另外

proxy_next_upstream error timeout http_500 non_idempotent

non_idemponent ,Nginx 默认对 non-idempotent 请求,比如 POST /LOCK/PATCH,是不进行重试。常见的情况就是 POST 请求出错后不会重试,需要加上该设置。

官方文档的说明是:

normally, requests with a non-idempotent method (POST, LOCK, PATCH) are not passed to the next server if a request has been sent to an upstream server (1.9.13)enabling this option explicitly allows retrying such requests

意思是如果不加上non_idempotent,对POST这些不幂等的方法,出错是不会重试的。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11654760.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存