nginx的配置文件
#user nobody;
worker_processes 1;
#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;
#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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream web_app{
server 192.168.84.130:8080 max_fails=2 fail_timeout=30s weight=1;
server 192.168.84.131:8080 max_fails=2 fail_timeout=30s weight=1;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
#定义首页索引文件的名称
index index.html index.htm index.jsp login.jsp;
#请求转向suroot定义的服务器列表
proxy_pass http://web_app;
#以下是一些反向代理的配置可删除.
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;#允许客户端请求的最大单文件字节数
client_body_buffer_size 128k;#缓冲区代理缓冲用户端请求的最大字节数,
proxy_connect_timeout 600;#nginx跟后端服务器连接超时时间(代理连接超时)
proxy_send_timeout 600; #后端服务器数据回传时间(代理发送超时)
proxy_read_timeout 600; #连接成功后,后端服务器响应时间(代理接收超时)
proxy_buffer_size 8k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers 4 64k;#proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
proxy_busy_buffers_size 128k;#高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size 128k;#设定缓存文件夹大小,大于这个值,将从upstream服务器传
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
nginx启动后的状态
[root@localhost nginx]# systemctl start nginx
[root@localhost nginx]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/nginx.service.d
└─override.conf
Active: active (running) since 六 2018-04-14 14:28:53 CST; 5s ago
Process: 11778 ExecStartPost=/bin/sleep 0.1 (code=exited, status=0/SUCCESS)
Process: 11775 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 11773 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 11772 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 11777 (nginx)
CGroup: /system.slice/nginx.service
├─11777 nginx: master process /usr/sbin/nginx
└─11779 nginx: worker process
4月 14 14:28:53 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server...
4月 14 14:28:53 localhost.localdomain nginx[11773]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
4月 14 14:28:53 localhost.localdomain nginx[11773]: nginx: configuration file /etc/nginx/nginx.conf test is successful
4月 14 14:28:53 localhost.localdomain systemd[1]: Started The nginx HTTP and reverse proxy server.
在浏览器中打开报错
nginx error!
The page you are looking for is temporarily unavailable. Please try again later.
Website Administrator
Something has triggered an error on your website. This is the default error page for nginx that is distributed with Fedora. It is located /usr/share/nginx/html/50x.html
You should customize this error page for your own site or edit the error_page directive in the nginx configuration file /etc/nginx/nginx.conf.
http://192.168.84.130:8080/
http://192.168.84.131:8080/
这两台分别是我在虚拟机中tomcat的路劲