一、基本环境配置
1.1、安装常用软件
yum install wget -y
1.2、Install yum repo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo yum clean all yum makecache
1.3、close firewalld
systemctl disable firewalld systemctl disable NetworkManager and sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g‘ /etc/selinux/config setenforce 0
1.4、安装常用软件
yum install net-tools vim lrzsz screen lsof tcpdump nc mtr nmap -y yum update -y && reboot
二、安装nginx
官网地址:http://nginx.org/en/download.html
2.1、yum方式安装:
yum install nginx -y
2.2、配置nginx
#配置nginx
[[email protected] ~]# vi /etc/nginx/nginx.conf
#指定配置文件: root /usr/share/nginx/html
#网站存放路径
[[email protected] html]# cd /usr/share/nginx/html
[[email protected] html]# ll
total 24
-rw-r--r-- 1 root root 3650 Mar 6 17:26 404.html
-rw-r--r-- 1 root root 3693 Mar 6 17:26 50x.html
-rw-r--r-- 1 root root 14 Jun 18 16:28 index.html
-rw-r--r-- 1 root root 3700 Mar 6 17:26 index.html.bak
-rw-r--r-- 1 root root 368 Mar 6 17:26 nginx-logo.png
-rw-r--r-- 1 root root 2811 Mar 6 17:26 poweredby.png
#改写主页
[[email protected] html]# echo "welcome nginx" >index.html
[[email protected] html]# cat index.html
welcome nginx
#启动服务
[[email protected] html]# systemctl restart nginx
[[email protected] html]# systemctl status nginx
#访问网站
http://192.168.56.33/ welcome nginx
#配置负载均衡
参考官网:
http://nginx.org/en/docs/http/load_balancing.html
http { upstream myapp1 { server srv1.example.com; server srv2.example.com; server srv3.example.com; } server { listen 80; location / { proxy_pass http://myapp1; } } }
#重启服务
systemc reload nginx
3、编译安装nginx
参考峰哥:http://www.cnblogs.com/linhaifeng/articles/6045600.html#_label19
源码安装: yum install gcc-* glibc-* openssl openssl-devel pcre pcre-devel zlib zlib-devel -y ls tar xvf nginx-1.10.3.tar.gz cd nginx-1.10.3 ls ./configure ./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --without-http_rewrite_module #--without-http_rewrite_module代表不使用重写功能,即不会引用pcre库,如果安装过程中出现pcre相关问题,可以指定该参数 make make install
#所有模块
参考:http://nginx.org/en/docs/
原文地址:https://www.cnblogs.com/nulige/p/9194378.html