nginx安装及使用

rustling / 2023-05-16 / 原文

Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器。

官网: https://nginx.org/en/download.html

安装

# 在Debian10上安装nginx
apt install nginx
# 查看版本
nginx -v
nginx version: nginx/1.14.2
# 启动 /usr/sbin/nginx
nginx
# 指定配置文件启动
nginx -c /etc/nginx/nginx.conf
# 查看进程
ps aux | grep nginx
# 停止
nginx -s stop

配置文件

默认配置文件路径: /etc/nginx/nginx.conf

...
# 应用服务器
upstream  app_service  { 
    #ip_hash; 
    server   192.168.10.100:8080 max_fails=2 fail_timeout=30s ;  
    server   192.168.10.101:8080 max_fails=2 fail_timeout=30s ;  
}
# 代理访问地址: localhost:8080
server {
    listen       80;
    server_name  localhost;
    location / {
        proxy_pass        http://app_service;  
    }
}
...