安装位置:/usr/local/nginx
nginx安装包下载地址:http://nginx.org/download/nginx-1.7.11.tar.gz
安装nginx前,需要确保系统安装了g++、gcc、openssl-devel、pcre-devel和zlib-devel软件。
yum install gcc-c++
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
下载nginx安装包
wget http://nginx.org/download/nginx-1.7.11.tar.gz
安装nginx到/usr/local文件夹下
[root@admin local]# cd /usr/local
[root@admin local]# tar -zxv -f nginx-1.7.11.tar.gz
[root@admin local]# rm -rf nginx-1.7.11.tar.gz
[root@admin local]# mv nginx-1.7.11 nginx
[root@admin local]# cd /usr/local/nginx
[root@admin nginx]# ./configure --prefix=/usr/local/nginx
[root@admin nginx]# make
[root@admin nginx]# make install
修改防火墙配置:
vi + /etc/sysconfig/iptables
在该文件中添加配置项
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
重启防火墙
[root@admin nginx-1.2.6]# service iptables restart
进入 /usr/local/nginx/conf 目录,在该目录下创建include 文件下,把配置文件写在这个文件夹里面
进入 /usr/local/nginx/conf/include 目录,创建 nginx.node.conf 文件,在里面输入如下代码:
```
upstream nodejs {
server 127.0.0.1:3000;
#server 127.0.0.1:3001;
keepalive 64;
}
server {
listen 80;
server_name www.penguu.com penguu.com;
access_log /var/log/nginx/test.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_set_header Connection "";
proxy_pass http://nodejs;
}
进入/usr/local/nginx/conf ,打开nginx.conf, 在http 里面添加 include /usr/local/nginx/conf/include/*
方法一
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
方法2
cd /usr/local/nginx/sbin
./nginx