搭建Nginx服务器

yum  list | grep pcre     ( 在yum中选出和pcre相关的东西,带@表示已经安装,[ ] 表示yum里的包 )

*在加压运行Nginx包前先把所需要的依赖环境装好:(gcc<c语言解释> pcre-devel openssl-devel)
[root@proxy ~]# yum -y install gcc pcre-devel openssl-devel        //安装依赖包
*装好后 建立一个普通用户寄存nginx服务器(为了安全)
[root@proxy ~]# useradd -s /sbin/nologin nginx
用tar解压tar.gz结尾的包
[root@proxy ~]# tar  -xf   nginx-1.10.3.tar.gz

用cd切换到当前解压的包里面操作一个脚本
[root@proxy ~]# cd  nginx-1.10.3

ls 查看是否有那个脚本./configure

[root@proxy nginx-1.10.3]# ./configure   \
命令行通过脚本转义符后跟指定路径( --x=/x/x/)以及模块(  --with-模块)
> --prefix=/usr/local/nginx   \                //指定安装路径
> --user=nginx   \                            //指定用户
> --group=nginx  \                            //指定组
> --with-http_ssl_module                        //开启SSL加密功能

解析
make(解析的是src里的源代码,解析完后放在objs里面)
安装(/usr/local/ngxin/有conf配置文件,html网页,logs日志,sbin主程序)
make install(放在/usr/local/ngxin/logs里面)

nginx使用方式
[root@proxy ~]# /usr/local/nginx/sbin / nginx                    //启动服务
[root@proxy ~]# /usr/local/nginx/sbin/ nginx -s stop            //关闭服务
[root@proxy ~]# /usr/local/nginx/sbin/nginx -s reload        //重新加载配置文件
[root@proxy ~]# /usr/local/nginx/sbin/nginx –V                //查看软件信息

为了方便用ln -s 做个软连接
ln -s /usr/local/nginx/sbin/nginx   /sbin/
以后输入nginx -V 即可查看软件信息(也可以看看前面的人是装的那些模块)
nginx ,nginx -s reload

查看端口信息 netstat  -antulp  |  grep nginx     (最好用ss -antulp | grep nginx)
-a显示所有端口的信息
-n以数字格式显示端口号
-t显示TCP连接的端口
-u显示UDP连接的端口
-l显示服务正在监听的端口信息,如httpd启动后,会一直监听80端口
-p显示监听端口的服务名称是什么(也就是程序名称)
nginx服务默认通过TCP 80端口监听客户端请求:

关闭防火墙,selinux
[root@proxy ~]# firewall-cmd --set-default-zone=trusted
[root@proxy ~]# setenforce 0
               或iptabls -F
测试
curl http://192.168.4.5
If you see this page, the nginx web server is successfully installed 

猜你喜欢

转载自blog.csdn.net/weixin_42628856/article/details/81319505