首页服务器CentOS系统如何编译安装Nginx并设置根目录权限

CentOS系统如何编译安装Nginx并设置根目录权限

时间2024-03-21 19:15:03发布访客分类服务器浏览590
导读:相信很多人对“CentOS系统如何编译安装Nginx并设置根目录权限”都不太了解,下文有实例供大家参考,对大家了解操作过程或相关知识有一定的帮助,而且内容详细,逻辑清晰,接下来小编就为你详细解释一下这个问题。 一、 nginx安...
相信很多人对“CentOS系统如何编译安装Nginx并设置根目录权限”都不太了解,下文有实例供大家参考,对大家了解操作过程或相关知识有一定的帮助,而且内容详细,逻辑清晰,接下来小编就为你详细解释一下这个问题。

一、 nginx安装环境

yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel



该命令等效于下面4句:



1、 gcc 安装

安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc:

yum install gcc-c++

2、 PCRE pcre-devel 安装

PCRE(PerlCompatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。

yum install -y pcre pcre-devel



3、 zlib 安装

zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。

yum install -y zlib zlib-devel



4、OpenSSL 安装

OpenSSL是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。

yum install -y openssl openssl-devel





二、下载nginx



1.直接下载.tar.gz安装包,地址:https://nginx.org/en/download.html



2.使用wget命令下载1.10.1版本(推荐)。

wget -c https://nginx.org/download/nginx-1.10.1.tar.gz





三、安装



1、解压

tar -zxvf nginx-1.10.1.tar.gz

cd nginx-1.10.1



2、配置

其实在 nginx-1.10.1 版本中你就不需要去配置相关东西,默认就可以了。当然,如果你要自己配置目录也是可以的。

1.使用默认配置

./configure

输出:

nginx path prefix: "/usr/local/nginx"

nginx binary file: "/usr/local/nginx/sbin/nginx"

nginx modules path: "/usr/local/nginx/modules"

nginx configuration prefix: "/usr/local/nginx/conf"

nginx configuration file: "/usr/local/nginx/conf/nginx.conf"

nginx pid file: "/usr/local/nginx/logs/nginx.pid"

nginx error log file: "/usr/local/nginx/logs/error.log"

nginx http access log file: "/usr/local/nginx/logs/access.log"

nginx http client request body temporary files: "client_body_temp"

nginx http proxy temporary files: "proxy_temp"

nginx http fastcgi temporary files: "fastcgi_temp"

nginx http uwsgi temporary files: "uwsgi_temp"

nginx http scgi temporary files: "scgi_temp"



3、编译安装

make

make install


查找安装路径:"/usr/local/nginx



四、开放80端口、开放http服务,重启防火墙

firewall-cmd --zone=public --add-port=80/tcp --permanent

firewall-cmd --permanent --zone=public --add-service=http

firewall-cmd --reload

firewall-cmd --list-all #查看开放服务、端口中是否有http服务和80端口。



五、更改nginx访问根目录

安装完nginx服务器后发现nginx的根目录在 安装目录的/html/下(/usr/local/nginx/html/),但是对于部署文件来说,在该目录下是不太习惯的,我就尝试着更改nginx访问的根目录



1、更改nginx配置文件

vi /usr/local/nginx/conf/nginx.conf

更改如下:

server {

listen 80;

server_name localhost;

location / {

root /home/ftpuser/wwwRoot; #新的根目录

index index.html index.htm index.jpg; #添加一张图片,测试用。

}


2、nginx根目录权限设置:

chmod -R 755 /home/ftpuser/wwwRoot/





3、重启nginx务器

service nginx restart



4、测试



拷贝一直张jpg格式图片到:/home/ftpuser/wwwRoot/目录下,改名为:index.jpg 。

chmod 744 /home/ftpuser/wwwRoot/index.jpg #设置所有人可读。

访问http://localhost/,图片即在网页中显示出来。

设置完成后此时访问http://localhost/XXX 即为/home/www/XXX



六、使用nginx

1 启动nginx

/usr/local/nginx/sbin/nginx



注意:执行/usr/local/nginx/sbin/nginx,这里可以-c指定加载的nginx配置文件,如下:

/usr/local/nginx/sbin/nginx -c /xxxxx

如果不指定-c,nginx在启动时默认加载/usr/local/nginx/conf/nginx.conf文件。





2 停止nginx

/usr/local/nginx/sbin/nginx -s quit

此方式停止步骤是待nginx进程处理任务完毕进行停止。





3 重启nginx:先停止再启动

/usr/local/nginx/sbin/nginx -s quit

/usr/local/nginx/sbin/nginx


感谢各位的阅读,以上就是“CentOS系统如何编译安装Nginx并设置根目录权限”的内容了,通过以上内容的阐述,相信大家对CentOS系统如何编译安装Nginx并设置根目录权限已经有了进一步的了解,如果想要了解更多相关的内容,欢迎关注网络,网络将为大家推送更多相关知识点的文章。

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: CentOS系统如何编译安装Nginx并设置根目录权限
本文地址: https://pptw.com/jishu/649468.html
CentOS系统如何安装配置redmine项目管理? 网站要开启https协议,如何在CentOS系统配置Nginx ?

游客 回复需填写必要信息