nginx简易配置

cooolr 于 2019-09-03 发布

http://nginx.org/en/download.html

yum install -y pcre pcre-devel openssl openssl-devel

tar -xf nginx-1.14.0.tar.gz 
cd nginx-1.14.0/

./configure --prefix=/usr/local/nginx  --with-http_stub_status_module --with-http_ssl_module

make && make install 

vim /usr/local/nginx/conf/nginx.conf

关键配置

http{

     upstream  web {
        server 127.0.0.1:1002;
        server 127.0.0.1:1003;
        server 127.0.0.1:1004;
        }   

    server {
        listen       1001;
        location / {
                proxy_pass http://web; # 负载均衡
                # return 301 http://baidu.com # 重定向
                # rewrite ^ https://lr.cool/$request_uri break; # 完整url重定向
        }
}
# 检查配置文件语法
/usr/local/nginx/sbin/nginx -t 
# 启动
/usr/local/nginx/sbin/nginx
# 重启
/usr/local/nginx/sbin/nginx -s reload