Nginx

一、简介

Nginx是一个高性能的HTTP和反向代理WEB服务器,同时也提供了IMAP/POP3/SMTP服务,主要用于WEB静态资源服务器(CSS、JS、HTML),负载均衡,反向代理,官方网址:http://nginx.org/。

二、启动服务器
start nginx -> 启动指令,窗口一闪而过
tasklist /fi "imagename eq nginx.exe" -> 查看进程是否存在
nginx -t -c ./conf/nginx.conf -> 检测配置文件是否正确
nginx -s reload -> 重启
nginx -s stop -> 快速关闭,窗口一闪而过
nginx -s quit -> 完整关闭,窗口一闪而过
Nginx_第1张图片
operate
访问地址:http://localhost:80,成功会出现下列文字
Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working.
Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.
失败查看错误日志
D:\Program Files\nginx-1.17.4\logs\error.log
1、端口号冲突
2、启动路径包含非法字符
三、反向代理
自定义配置文件(./nginx-1.17.4/conf/nginx_wjx.conf)
upstream nginx_wjx {
    server 192.168.1.100:8080; -> Tomcat的访问路径
}

server {
    listen 555;
    server_name  192.168.1.100; -> 用户的访问路径
    root   html;
    index  index.html index.htm index.php;
    location / { -> 反向代理配置
        proxy_pass  http://nginx_wjx;
        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;
        proxy_next_upstream error timeout invalid_header http_500;
        proxy_max_temp_file_size   0;
        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;
        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;
   }
}

主配置文件(./nginx-1.17.4/conf/nginx.conf)
http {
    include nginx_wjx.conf;
}
四、负载均衡
upstream nginx_wjx { -> 配置多个Tomcat的访问路径
    server 192.168.1.100:8080 down; -> 当前服务器不参与负载
    server 192.168.1.100:8081 weight=1; -> 服务器负载比重
    server 192.168.1.100:8082 backup; -> 服务器压力最轻
}

你可能感兴趣的:(Nginx)