NGINX笔记
2018-11-01 本文已影响0人
SithCait
服务器市场份额
命令
http://www.nginx.cn/nginxchscommandline
LINUX使用步骤








配置文件
#user nobody;
worker_processes 4;//工作进程,设置为cpu核心数量
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
#一个进程允许多少连接
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#access_log logs/access.log main;
#减少内核读取
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#压缩功能,并发量大的时候体现
#gzip on;
upstream manager {
server localhost:8200 weight=1 max_fails=5 fail_timeout=30s;
server localhost:8201 weight=1 max_fails=5 fail_timeout=30s;
#server localhost:8203 backup;
#server localhost:8204 down;
#server localhost:8205 max_conns=1000;
}
upstream portal {
server localhost:8100 weight=1 max_fails=5 fail_timeout=30s;
server localhost:8101 weight=1 max_fails=5 fail_timeout=30s;
}
server {
listen 80;
server_name www.myshop.com;
#设置host转发防止tomcat获取不到域名
proxy_set_header Host $host;
location / {
proxy_pass http://portal;
index index.html index.htm;
}
#图片缓存
#location ~* \.(gif|jpg|png)$ {
# expires 30d;
#}
}
server {
listen 80;
#server_name 192.168.2.200 #基于ip
server_name admin.myshop.com;
#设置host转发防止tomcat获取不到域名
proxy_set_header Host $host;
location / {
proxy_pass http://manager;
index index.html index.htm;
}
#图片缓存
#location ~* \.(gif|jpg|png)$ {
# expires 30d;
#}
}
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
rewrite指令
https://blog.csdn.net/lchpersonal521/article/details/81451562





缓存、限速、日志
日志切割脚本
-usr1
反向代理
LOCATION



gzip压缩

expires缓存
放在localion体里

浏览器先对服务器请求,返回304告诉浏览器未过期可以直接取本地。
expires设置后,服务器设置资源过期时间,浏览器直接从磁盘取,不请求服务器。