Linux| Nginx安装,配置开机自动启动

一、Nginx安装步骤

官网下载:http://nginx.org/en/download.html

#step1:下载nginx安装包,本人选择nginx-1.10.3.tar.gz
[root@localhost ~]$ cd /usr/local/src/
[root@localhost src]$ wget http://nginx.org/download/nginx-1.10.3.tar.gz
#step2:安装依赖【可用 yum list installed | grep "软件名或者包名" 查找是否安装过】
[root@localhost src]$ yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
#step3:nginx安装包解压缩
[root@localhost src]$ tar -xzvf nginx-1.10.3.tar.gz
#step4:进入nginx目录,执行配置
[root@localhost src]$ cd nginx-1.10.3
[root@localhost nginx-1.10.3]$ ./configure
#step5:编译
[root@localhost nginx-1.10.3]$ make
#step6:安装 (默认安装目录/usr/local/nginx,进入/usr/local/可查看到存在nginx)
[root@localhost nginx-1.10.3]$ make install

二、启动Nginx

#step1:启动Nginx
[root@localhost nginx]$ /usr/local/nginx/sbin/nginx
#step2:查看Nginx是否启动
[root@localhost nginx ]$ ps -ef|grep nginx
root       1077      1  0 00:52 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody     1089   1077  0 00:52 ?        00:00:00 nginx: worker process
hadoop     3468   2523  0 01:44 pts/0    00:00:00 grep --color=auto nginx

浏览器中输入服务器的ip地址,如:http://192.168.203.10/
若无法访问,则需要查看nginx端口是否打开。可本地telnet端口号:telnet ip 80进行查看。若nginx端口号无法访问,则进行防火墙配置

注:nginx默认端口80,可从配置文件nginx.conf中查看,也可修改默认端口
nginx主配置文件:/usr/local/nginx/conf/nginx.conf
nginx日志文件:/usr/local/nginx/logs/access.log

三、防火墙

关闭防火墙:systemctl stop firewalld
或者配置防火墙:

#step1:开放80端口,--permanent 永久生效,没有此参数重启后失效
firewall-cmd --add-port=80/tcp --permanent
#step2:重启防火墙
systemctl restart firewalld

防火墙配置后,浏览器输入服务器的ip地址,如:http://192.168.203.10/,显示如下,说明nginx启动成功!


Linux| Nginx安装,配置开机自动启动_第1张图片
图片.png

四、设置开机自动启动Nginx

#step1:在etc/rc.d/rc.local中添加nginx启动命令,
[root@localhost nginx ]$ vim /etc/rc.d/rc.local
Linux| Nginx安装,配置开机自动启动_第2张图片
rc.local添加内容.png
#step2:修改/etc/rc.d/rc.local的可执行权限
chmod +x /etc/rc.d/rc.local

重启: reboot 或者 init 6 查看是否自动启动Nginx服务

参考链接:
https://www.jianshu.com/p/9f2c162ac77c
https://www.cnblogs.com/xxoome/p/5866475.html

你可能感兴趣的:(Linux| Nginx安装,配置开机自动启动)