linux安装nginx(傻瓜式)

推荐全程使用root用户操作,避免nginx启动成功后,浏览器访问提示304,没有权限访问html文件夹页面

1. Nginx 官网地址

http://nginx.org/en/download.html

2.上传安装包

如:/data/software/nginx-1.18.0.tar.gz

3.解压Nginx 压缩文件

tar -zxvf /data/software/nginx-1.18.0.tar.gz

4.移动解压包到安装目录

mv /data/software/nginx-1.18.0 /usr/local

5.安装nginx服务器

源码的安装通常由3个步骤组成:配置(configure)、编译(make)、安装(make install)。

#进入到安装包目录
cd /usr/local/nginx-1.18.0

#配置configure --prefix 代表安装的路径,--with-http_ssl_module 安装ssl,--with-http_stub_status_module查看nginx的客户端状态
[root@wt nginx]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module
[root@wt nginx]# make
[root@wt nginx]# make install

安装成功后,生成执行目录/usr/local/nginx

或通过命令查看安装路径: whereis nginx

6.执行启动nginx

Linux命令:
	1.启动命令:    ./nginx
	2.重启命令:   ./nginx -s reload
	3.关闭命令:   ./nginx -s stop

7.设置开机启动(不需要可忽略该步骤)
vim /lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target  

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

辅助操作:

A.更改文件(目录)权限:

chmod 755  <文件名>  其中,7=r+w+x,5=r+x,5=r+x。

chmod 755 /usr/local/nginx -R

B.所属者(组)的改变:

chown     {参数}    所有者:所属组    文件/目录

chown root:root /usr/local/nginx -R

C.对于目录来说,存在多级目录的,可以添加“-R”参数

yum -y install gcc gcc-c++ autoconf automake make

yum -y install openssl openssl-devel

1、原创文章,作者:诺米,如若转载,请注明出处:https://www.http3w.com/archives/875

2、本站内容若有雷同从属巧合,若侵犯了您的权益,请联系本站删除,E-mail: wtao219@qq.com

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注