配置文件
- 主文件:
/etc/nginx/nginx.config
例當前在22.22.22.4服務器
//同時開另外三個服務器
能夠在http{} 裏添加 include /etc/nginx/sites-enabled/*;
而後在 /etc/nginx/sites-enabled/default 中配置
upstream project {
server 22.22.22.2:3000;
server 22.22.22.3:3000;
server 22.22.22.5:3000;
}
server {
listen 80;
location / {
proxy_pass http://project;
}
#緩存
location ~* \.(css|js|gif|jpe?g|png)$ {
expire 168h;
}
location /api {
expires 10m;
}
}
//測試
ab -c 40 -n -1000 http://22.22.22.4/
- 啓用:
nginx -s start / service nginx start
- 重啓:
nginx -s reload / service nginx reload
- centos7下的操做
- 開啓服務:
systemctl start nginx.service
- 查看狀態:
systemctl status nginx
- 查看錯誤日誌:
cat /var/log/nginx/error.log
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080