rpm安装:
http://shmily2038.iteye.com/blog/1860063
1、CentOS 6,先执行:
rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
2,查看yum的nginx信息
[]# yum info nginx
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirror.esocc.com
* extras: mirror.esocc.com
* updates: mirror.esocc.com
base | 3.7 kB 00:00
base/primary_db | 4.4 MB 00:28
extras | 3.5 kB 00:00
extras/primary_db | 19 kB 00:00
nginx | 2.9 kB 00:00
nginx/primary_db | 22 kB 00:00
updates | 3.5 kB 00:00
updates/primary_db | 2.1 MB 00:10
Installed Packages
Name : nginx
Arch : x86_64
Version : 1.4.0
Release : 1.el6.ngx
Size : 874 k
Repo : installed
From repo : nginx
Summary : nginx is a high performance web server
URL : http://nginx.org/
License : 2-clause BSD-like license
Description : nginx [engine x] is an HTTP and reverse proxy server, as well as
: a mail proxy server
3,安装并启动nignx
[root@server ~]# yum install nginx
[root@server ~]# service nginx start
Starting nginx: [ OK ]
4,然后进入浏览器,输入http://192.168.0.161/测试,如果看到
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
恭喜你,你成功了!
如果不能连接到nginx,原因很多,但是可以先检查 1,nginx服务是否真的起来了;2,linux服务器防火墙是否打开
修改以下配置才可以打开页面
#修改防火墙配置:
[root@admin nginx-1.2.6]# 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
重启若出现:
iptables: Applying firewall rules: iptables-restore: line 14 failed
[FAILED]
解决办法:将
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
放在“COMMIT”之前:
注意添加位置/
已经在:/etc/sysconfig/iptables
添加:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
开启防火墙还是无法访问
关闭防火墙才有
Welcome to nginx!
解决:
你是使用-A选项,表示追加,你可以用iptables -n -L 查看一下,估计你是添加到最后一行了。iptables判断规则是从上往下判断的,你这条规则上面应该有一条REJECT规则,你添加的规则必须在这条规则之前。
///
源码安装:
http://www.cnblogs.com/zhoulf/archive/2013/02/09/2909653.html
安装说明
系统环境:CentOS-6.3
软件:nginx-1.2.6.tar.gz
安装方式:源码编译安装
安装位置:/usr/local/nginx
下载地址:http://nginx.org/en/download.html
安装前提
在安装nginx前,需要确保系统安装了g++、gcc、openssl-devel、pcre-devel和zlib-devel软件。安装必须软件:
[root@admin /]#yum install gcc-c++ yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel |
检查系统安装的Nginx:
[root@admin local]# find -name nginx ./nginx ./nginx/sbin/nginx ./nginx-1.2.6/objs/nginx |
卸载原有的Nginx
[root@admin /]# yum remove nginx |
安装
将安装包文件上传到/usr/local中执行以下操作:
[root@admin local]# cd /usr/local [root@admin local]# tar -zxv -f nginx-1.2.6.tar.gz [root@admin local]# rm -rf nginx-1.2.6.tar.gz [root@admin local]# mv nginx-1.2.6 nginx [root@admin local]# cd /usr/local/nginx [root@admin nginx]# ./configure --prefix=/usr/local/nginx [root@admin nginx]# make // 出现:make[1]: Entering directory `/usr/local/nginx' [root@admin nginx]# make install |
配置
#修改防火墙配置: [root@admin nginx-1.2.6]# 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 |
启动
#方法1 |
停止
#查询nginx主进程号 |
重启
[root@admin local]# /usr/local/nginx/sbin/nginx -s reload |
测试
#测试端口 |
反向代理无法登录问题:
需要设置 proxy_cookie_path /api/ /; #/api/ 是context 路径, /是 cookie路径
参考:https://www.cnblogs.com/wangdaijun/p/5579751.html