Nginx-----系列(三)

简介: 首先要关闭Linux中的防火墙 关闭防火墙(临时关闭): systemctl stop firewalld.service 查看是否关闭防火墙: systemctl status firewalld.service

1.Nginx启动与关闭(基础版)

首先要关闭Linux中的防火墙       关闭防火墙(临时关闭):   systemctl stop firewalld.service  

                                                     查看是否关闭防火墙: systemctl status firewalld.service

2345_image_file_copy_196.jpg

永久关闭 (即设置开机的时候不自动启动)   systemctl disable firewalld.service

 使用systemctl查看开启的firewalld服务 (管道符)    systemctl list-unit-files |grep firewalld

开启nginx:./nginx

查看nginx启动状态:ps aux|grep nginx

2345_image_file_copy_197.jpg测试成功

2345_image_file_copy_198.jpg

立即停止服务
这种方法比较强硬,无论进程是否在工作,都直接停止进程。
[root@localhost sbin]# ./nginx -s stop
从容停止服务
这种方法较stop相比就比较温和一些了,需要进程完成当前工作后再停止。
[root@localhost sbin]# ./nginx -s quit
killall 方法杀死进程
直接杀死进程,在上面无效的情况下使用,态度强硬,简单粗暴!
[root@localhost sbin]# killall nginx

关闭成功

2345_image_file_copy_200.jpg

2.Nginx启动与关闭(高级版----开机自启动)

2.1 设置开机自启动

进到系统服务添加路径:[root@localhost sbin]# cd /usr/lib/systemd/system/

2.2 建立服务文件nginx.service

注意nginx 的安装路径保持一样: /usr/local/nginx/

[root@localhost system]# vim nginx.service
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target

2345_image_file_copy_201.jpg

2345_image_file_copy_202.jpg

给刚刚创建的nginx.seriver  添加权限 :chmod +x nginx.service  添加自定义权限文件会变绿

2345_image_file_copy_203.jpg

现在创建的 nginx.service 禁言状态

2345_image_file_copy_204.jpg

 如果想变成自启动需要: systemctl enable nginx

2345_image_file_copy_205.jpg

2345_image_file_copy_206.jpg

可以用  journalctl -xe  查看端口是否启动

2345_image_file_copy_207.jpg

2345_image_file_copy_208.jpg

2345_image_file_copy_209.jpg

2345_image_file_copy_210.jpg

然后输入 命令 systemctl restart nginx 重启一下

目录
相关文章
|
8月前
|
缓存 负载均衡 前端开发
Nginx
Nginx
54 0
|
9月前
|
负载均衡 JavaScript 应用服务中间件
nginx使用
nginx使用
|
9月前
|
缓存 负载均衡 应用服务中间件
Nginx(一)
Nginx(一)
86 0
|
负载均衡 应用服务中间件 nginx
|
应用服务中间件 网络安全 nginx
nginx应用
nginx应用
126 0
|
缓存 负载均衡 算法
Nginx——详解
Nginx是lgor Sysoev为俄罗斯访问量第二的rambler.ru站点设计开发的。从2004年发布至今,凭借开源的力量,已经接近成熟与完善。
160 0
Nginx——详解
|
存储 机器学习/深度学习 负载均衡
nginx几个简单问题
《基础系列》
131 0
|
缓存 负载均衡 前端开发
|
存储 缓存 安全
Nginx基本应用(一)
Nginx基本应用(一)
Nginx基本应用(一)
|
应用服务中间件 nginx
Nginx的使用
Nginx的使用
128 0
Nginx的使用