把nginx软件传输到Linux虚拟机上面
解压 tar -zxvf nginx-1.5.9.tar.gz 过后
进入
cd nginx-1.5.9 nginx目录
输入下方命令 配置环境
./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx
执行此段命令后报错
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
安装pcre-devel解决问题
yum -y install pcre-devel
在执行配置环境命令
还有可能出现:
错误提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.
解决办法:
yum -y install openssl openssl-devel
执行编译安装
make && make install
编译完成后
输入 nginx 启动nginx
查看nginx是否启动
ps -ef | grep nginx
root 6937 1 0 18:01 ? 00:00:00 nginx: master process nginx
nobody 6938 6937 0 18:01 ? 00:00:00 nginx: worker process
root 6941 2173 0 18:01 pts/0 00:00:00 grep nginx
看到2个进程说明启动成功
第一个master进程起到本地监控的作用监控管理nginx
worker进程作为正真服务的进程
chkconfig iptables off 开机时不启动防火墙
临时关闭防火墙 service iptables off
查看防火墙状态
service iptables status
重启后运行
iptables:未运行防火墙。
配置域名完成后
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;//>
server {
listen 80;
server_name manage.leyou.com;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://127.0.0.1:9001;
proxy_connect_timeout 600;
proxy_read_timeout 600;
}
}
server {
listen 80;
server_name api.leyou.com;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://127.0.0.1:10010;
proxy_connect_timeout 600;
proxy_read_timeout 600;
}
}
}
配置的地址需要在
/opt/nginx/conf
修改配置