1、nginx的nginx.conf配置文件有幾個主要部分:
一、http{}
二、http{}內包含了 server {}
三、server {} 內包含了location / {} html
2、nginx.conf 範本:node
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;nginx
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;app
server {
listen 80 default_server;
server_name 192.168.31.222;
root /usr/share/nginx/html;jsp
** location / **{ } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { }
* include /etc/nginx/conf.d/.conf;**
}tcp
3、 子配置文件範本:
upstream bakend {
ip_hash;ide
server 192.168.31.203:8080 weight=10 max_fails=3 fail_timeout=10s;
server 192.168.31.204:8080 weight=20 max_fails=3 fail_timeout=10s;
}code
server {
listen 80;
server_name 192.168.31.222;
location / {
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect default;
root html;
index index.jsp;
}
}orm