1、配置首先需要配置相关环境:
Yum install gcc-c++
Yum install –y pcre pcre-devel
Yum install –y zlib zlib-devel
Yum install –y openssl openssl-devel
2、下载nginx源码包 :https://nginx.org/en/download.html (复制到/目录下)
3、配置
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
4、make & make install
5、nginx.conf配置
6、通过域名配置nginx.conf
在本机或服务器配置host 文件: windows/System32/drivers/etc/host
Eg: 192.168.86.131(虚拟机IP) tom.taotao.com
7、在nginx.conf里配置
server {
listen 80;
server_name test3.taotao.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html-test3;
index index.html index.htm;
}
}
8、负载均衡
启动: /usr/local/nginx/sbin/./nginx
重新加载配置: /usr/local/nginx/sbin/./nginx –s reload
停用配置: /usr/local/nginx/sbin/./nginx –s stop
参考网页: http://www.linuxidc.com/Linux/2016-09/134907.htm
当重新启动虚拟机的时候可能会出现nginx.pid 丢失的情况,解决方法如下:
- 到/var/run下看没有nginx这个目录,创建/var/run/nginx,再启动。
重启虚拟机,这个目录会被删掉。
2、在nginx下创建logs目录,进入ningx.conf,将pid logs/nginx.pid前注释去掉