nginx

nginx
nginx重启
/usr/local/nginx/sbin/nginx -s reload
配置检测
nginx -t -c /usr/nginx/conf/nginx.conf 或 /usr/local/nginx/sbin/nginx -t
服务器频繁出现502,查看nginx连接数
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
TIME_WAIT:另一边已初始化一个释放。这个是啥意思呢?意思就是服务器已经主动关闭了,在等待客户端给一个回应,如果客户端一直没有回应就会出现等待,这个值就会增加。修改mysql配置文件,调整max_connection为30000。查看mysql中的进程,发现频繁的sql查询,而所查询的几个表数据量均在10万左右,判断是因为没有设置索引导致。
504 Gateway Time-out
虚拟主机配置添加:
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 256k;
fastcgi_buffers 8 128k;
client_body_buffer_size 1024k;
child process failed, exited with error number 1
日志是文件
解决 recv() failed (104: Connection reset by peer) while reading response header from upstream
vi /phpstudy/server/php/etc/php-fpm.conf
修改 request_terminate_timeout = 0
nginx修改上传文件大小限制
location / {  
          加上   client_max_body_size    1000m;  
nginx对指定目录做代理
环境介绍
web1,作为前端端服务器,访问地址是http://192.168.1.1,要将http://192.168.1.1/bbs的请求交给web2。在web1的网站根目录下并没有bbs目录
web2,作为后端web服务器,访问地址是http://192.168.1.2
web1配置location 方式一
location /bbs/ {
proxy_pass http://192.168.1.2/;             #有“/”
}
效果:通过 http://192.168.1.1/bbs  可以访问到web2网站根目录下的内容
web1配置location 方式二
如果在web1中加入location中多少加 “/”
location /bbs/ {
proxy_pass http://192.168.1.2;            #无“/”
}
效果:要通过web1反问web2网站根目录的内容则需要输入:http://192.168.1.1/bbs/bbs
nginx:负载均衡的session共享
1. 不使用session,使用cookie
2. session存在数据库mysql
3. session存在缓存memcache或者redis中
4. ip_hash技术
cp: omitting directory”错误的解释和解决办法
解决办法:递归拷贝  命令:cp -r bbs ../backup/bbs    解释:-r 这个options是递归的意思
nginx实现动态分离,解决css和js等图片加载问题
图片,css,js文件路径单独配置
nginx反向代理 取得真实IP和域名
nginx反向代理配置时,一般会添加下面的配置:
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Nginx配置跨域请求 Access-Control-Allow-Origin *
location / {  
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
    add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
 
    if ($request_method = 'OPTIONS') {
        return 204;
    }
}
配置phpmyadmin报错
location ^~ /mc/ {
        proxy_pass http://172.16.99.30:8088/;
        proxy_set_header   HOST             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
Nginx 支持webSocket 响应403
location /chat/ {
    proxy_pass http://backend;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}
proxy_pass_header X-XSRF-TOKEN;
proxy_set_header Origin "http://testsysten:8080";
原文地址:https://www.cnblogs.com/ssmd/p/9776636.html