CentOS7搭建Nginx服务(nginx版本:nginx-1.16.1)

1.下载并且解压源码包

[root@test2 /home/ops]#wget http://nginx.org/download/nginx-1.16.1.tar.gz
[root@test2 /home/ops]#tar -zxvf nginx-1.16.1.tar.gz

2.安装依赖包

[root@test2 /home/ops]#yum -y install gcc pcre-devel openssl-devel

3.开始安装

[root@test2 /home/ops]#cd nginx-1.16.1
[root@test2 /home/ops/nginx-1.16.1]#./configure --prefix=/home/ops/nginx --user=nginx --group=nginx --with-http_ssl_module --with-stream --with-http_stub_status_module

–prefix=/home/ops/nginx 指定安装路径
-user=nginx 指定用户
–group=nginx 指定组
–with-http_ssl_module 开启SSL加密功能
–with-stream 开启TCP/UDP代理模块
–with-http_stub_status_module 开启status状态页面
以上模块看需要添加,不是必须操作

[root@test2/home/ops/nginx-1.16.1]# make && make install
到此nginx编译安装完毕!

4.nginx命令的用法

nginx编译安装完之后启动命令放在安装路径下面的sbin目录下
例如我指定的安装路径为/home/ops/nginx,那么启动命令就放在/home/wuyoupin/data/server/nginx/sbin/下,有一个nginx 执行文件

1.给nginx服务启动命令做软链接,方便使用

ln -s /home/ops/nginx/sbin/nginx /usr/bin/nginx

2.nginx命令的用法:

nginx 启动服务
nginx -s stop 停止服务
nginx -s reload 重新加载配置文件
nginx -V 查看软件信息

5.启动服务,访问测试

[root@test2/home/ops/nginx-1.16.1]#nginx
检查端口:
[root@test2 /home/wuyoupin/data/server/nginx-1.16.1]#netstat -anptu | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 14923/nginx: master

访问测试:
浏览器输入服务器ip访问

出现403报错:

403 Forbidden

403 Forbidden


nginx/1.16.1

原因:目录权限没有给对,要注意nginx安装路径以上的所有目录,都要给对权限,我使用的是nginx用户,我的目录属于root用户,所以其他人的权限要至少有读跟执行的权限
解决:
[root@test2 /home/ops/nginx-1.16.1]#chmod -R 755 /home/
再次访问即可成功:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44901564/article/details/108170765
今日推荐