Nginx

推荐列表 站点导航

当前位置:首页 > 服务器技术 > Nginx >

详解基于CentOS 7配置Nginx自启动

来源:互联网  作者:网友投稿  发布时间:2021-01-09 03:51
这篇文章主要介绍了详解基于CentOS 7配置Nginx自启动,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟...

具体则是参考上面的链接或者上面给出的nginx.service文件内容。

也给大家做个参考,此处为编译安装 ? 1 # rpm -qa|grep nginx 也没有添加相应的自启动服务 ? 1 # systemctl list-unit-files |grep nginx nginx版本 ? 1 2 # /u01/app/nginx/sbin/nginx -v nginx version: nginx/1.8.1 获取nginx编译模块,如下查询,以确保服务器异常宕机后自动重启该服务,现在分享给大家,小编觉得挺不错的, 这篇文章主要介绍了详解基于CentOS 7配置Nginx自启动, 一、yum 安装方式Nginx自启动 当前环境 ? 1 2 [root@node142 ~]# more /etc/redhat-release CentOS Linux release 7.2.1511 (Core) 查看是否保护nginx rpm包 ? 1 2 3 4 5 6 7 8 9 10 [root@node142 ~]# rpm -qa|grep nginx nginx-mod-http-geoip-1.12.2-2.el7.x86_64 nginx-1.12.2-2.el7.x86_64 nginx-filesystem-1.12.2-2.el7.noarch nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64 nginx-mod-stream-1.12.2-2.el7.x86_64 nginx-mod-http-perl-1.12.2-2.el7.x86_64 nginx-mod-http-image-filter-1.12.2-2.el7.x86_64 nginx-all-modules-1.12.2-2.el7.noarch nginx-mod-mail-1.12.2-2.el7.x86_64 查看是否存在相应的服务,如下, 然后将其保存为 /lib/systemd/system/nginx.service,深受广大互联网企业以及IT运维人员所喜爱,然后查看诸如pid, status=0/SUCCESS) Process: 10586 ExecStartPre=http://www.zzvips.com/u01/app/nginx/sbin/nginx -t (code=exited,对于这个自启动的脚本我们需要自行配制,因此,Nginx需要手工配置自启动服务,以下描述的是基于CentOS 7下来配置自启动服务,有nginx.service ? 1 2 [root@node142 ~]# systemctl list-unit-files |grep nginx nginx.service disabled 将其配置为自动 ? 1 [root@node142 ~]# systemctl enable nginx.service 查看nginx.service文件 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 [root@node142 ~]# more /lib/systemd/system/nginx.service [Unit] Description=The nginx HTTP and reverse proxy server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=http://www.zzvips.com/run/nginx.pid # Nginx will fail to start if /run/nginx.pid already exists but has the wrong # SELinux context. This might happen when running `nginx -t` from the cmdline. # https://bugzilla.redhat.com/show_bug.cgi?id=1268621 ExecStartPre=http://www.zzvips.com/usr/bin/rm -f /run/nginx.pid ExecStartPre=http://www.zzvips.com/usr/sbin/nginx -t ExecStart=http://www.zzvips.com/usr/sbin/nginx ExecReload=http://www.zzvips.com/bin/kill -s HUP $MAINPID KillSignal=SIGQUIT TimeoutStopSec=5 KillMode=process PrivateTmp=true [Install] WantedBy=multi-user.target 上述配置文件中的内容和官网提供的一模一样 https://www.nginx.com/resources/wiki/start/topics/examples/systemd/ 二、编译安装后的自启动配置 由于是编译安装,短小精悍,二进制位置并记录以便修改启动文件 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 # /u01/app/nginx/sbin/nginx -V nginx version: nginx/1.8.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=http://www.zzvips.com/u01/app/nginx --sbin-path=http://www.zzvips.com/u01/app/nginx/sbin/nginx --conf-path=http://www.zzvips.com/u01/app/nginx/nginx.conf --error-log-path=http://www.zzvips.com/u01/app/nginx/log/error.log --http-log-path=http://www.zzvips.com/u01/app/nginx/log/access.log --pid-path=http://www.zzvips.com/u01/app/nginx/nginx.pid --lock-path=http://www.zzvips.com/u01/app/nginx/nginx.lock --http-client-body-temp-path=http://www.zzvips.com/u01/app/nginx/client_temp --http-proxy-temp-path=http://www.zzvips.com/u01/app/nginx/proxy_temp --http-fastcgi-temp-path=http://www.zzvips.com/u01/app/nginx/fastcgi_temp --http-uwsgi-temp-path=http://www.zzvips.com/u01/app/nginx/uwsgi_temp --http-scgi-temp-path=http://www.zzvips.com/u01/app/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_spdy_module --with-ipv6 下面我们生成一个新的nginx.service文件 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 # vim /lib/systemd/system/nginx.service [Unit] Description=The NGINX HTTP and reverse proxy server After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=http://www.zzvips.com/u01/app/nginx/nginx.pid ExecStartPre=http://www.zzvips.com/u01/app/nginx/sbin/nginx -t ExecStart=http://www.zzvips.com/u01/app/nginx/sbin/nginx ExecReload=http://www.zzvips.com/bin/kill -s HUP $MAINPID ExecStop=http://www.zzvips.com/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target 下面我们先手工停止nginx ? 1 # /u01/app/nginx/sbin/nginx -s stop 配置自启动 ? 1 # systemctl enable nginx.service 使用systemctl工具启动nginx服务 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 # systemctl start nginx.service # systemctl status nginx.service ● nginx.service - The NGINX HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2018-03-29 16:37:47 CST; 6s ago Process: 10588 ExecStart=http://www.zzvips.com/u01/app/nginx/sbin/nginx (code=exited,我们在生产环境基于编译方式安装Nginx后,它开源,很多时候,简单易用, 看下面的例子 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # more /etc/redhat-release CentOS Linux release 7.4.1708 (Core) # ps -ef|grep nginx root 10092 10014 0 16:23 pts/0 00:00:00 grep --color=auto nginx root 20791 1 0 Mar20 ? 00:00:00 nginx: master process ./sbin/nginx -c /u01/app/nginx/nginx.conf nobody 20792 20791 0 Mar20 ? 00:00:44 nginx: worker process nobody 20793 20791 0 Mar20 ? 00:00:42 nginx: worker process nobody 20794 20791 0 Mar20 ? 00:00:50 nginx: worker process nobody 20795 20791 0 Mar20 ? 00:00:44 nginx: worker process nobody 20796 20791 0 Mar20 ? 00:00:43 nginx: worker process nobody 20797 20791 0 Mar20 ? 00:00:43 nginx: worker process nobody 20798 20791 0 Mar20 ? 00:00:37 nginx: worker process nobody 20799 20791 0 Mar20 ? 00:00:48 nginx: worker process nobody 20800 20791 0 Mar20 ? 00:00:04 nginx: cache manager process # 无相应的rpm包,供大家参考,一起跟随小编过来看看吧 Nginx是广为流行的轻量级Web服务器软件, status=0/SUCCESS) Main PID: 10590 (nginx) CGroup: /system.slice/nginx.service ├─10590 nginx: master process /u01/app/nginx/sbin/nginx ├─10591 nginx: worker process # Author : Leshami ├─10592 nginx: worker process # Blog : https://blog.csdn.net/leshami ├─10593 nginx: worker process ├─10594 nginx: worker process ├─10595 nginx: worker process ├─10596 nginx: worker process ├─10597 nginx: worker process ├─10598 nginx: worker process ├─10599 nginx: cache manager process └─10600 nginx: cache loader process Mar 29 16:37:47 ydq-std systemd[1]: Starting The NGINX HTTP and reverse proxy server... Mar 29 16:37:47 ydq-std nginx[10586]: nginx: the configuration file /u01/app/nginx/nginx.conf syntax is ok Mar 29 16:37:47 ydq-std nginx[10586]: nginx: configuration file /u01/app/nginx/nginx.conf test is successful Mar 29 16:37:47 ydq-std systemd[1]: Started The NGINX HTTP and reverse proxy server. ,。

相关热词:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/server/nginx/12124.shtml

最新文章
并且强制用 HTTPS 访问 fa 并且强制用 HTTPS 访问 fa

时间:2021-01-14

可以控制访问量 可以控制访问量

时间:2021-01-14

(通配符在前) ③server (通配符在前) ③server

时间:2021-01-14

Nginx环境下WordPress的多站点 Nginx环境下WordPress的多站点

时间:2021-01-05

nginx keepalive的具体使用 nginx keepalive的具体使用

时间:2021-01-05

Nginx的信号控制 Nginx的信号控制

时间:2021-01-05

win10上安装nginx的方法步骤 win10上安装nginx的方法步骤

时间:2020-12-29

linux下 nginx监控问题 linux下 nginx监控问题

时间:2020-12-29

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

详解基于CentOS 7配置Nginx自启动

2021-01-09 编辑:网友投稿

具体则是参考上面的链接或者上面给出的nginx.service文件内容。

也给大家做个参考,此处为编译安装 ? 1 # rpm -qa|grep nginx 也没有添加相应的自启动服务 ? 1 # systemctl list-unit-files |grep nginx nginx版本 ? 1 2 # /u01/app/nginx/sbin/nginx -v nginx version: nginx/1.8.1 获取nginx编译模块,如下查询,以确保服务器异常宕机后自动重启该服务,现在分享给大家,小编觉得挺不错的, 这篇文章主要介绍了详解基于CentOS 7配置Nginx自启动, 一、yum 安装方式Nginx自启动 当前环境 ? 1 2 [root@node142 ~]# more /etc/redhat-release CentOS Linux release 7.2.1511 (Core) 查看是否保护nginx rpm包 ? 1 2 3 4 5 6 7 8 9 10 [root@node142 ~]# rpm -qa|grep nginx nginx-mod-http-geoip-1.12.2-2.el7.x86_64 nginx-1.12.2-2.el7.x86_64 nginx-filesystem-1.12.2-2.el7.noarch nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64 nginx-mod-stream-1.12.2-2.el7.x86_64 nginx-mod-http-perl-1.12.2-2.el7.x86_64 nginx-mod-http-image-filter-1.12.2-2.el7.x86_64 nginx-all-modules-1.12.2-2.el7.noarch nginx-mod-mail-1.12.2-2.el7.x86_64 查看是否存在相应的服务,如下, 然后将其保存为 /lib/systemd/system/nginx.service,深受广大互联网企业以及IT运维人员所喜爱,然后查看诸如pid, status=0/SUCCESS) Process: 10586 ExecStartPre=http://www.zzvips.com/u01/app/nginx/sbin/nginx -t (code=exited,对于这个自启动的脚本我们需要自行配制,因此,Nginx需要手工配置自启动服务,以下描述的是基于CentOS 7下来配置自启动服务,有nginx.service ? 1 2 [root@node142 ~]# systemctl list-unit-files |grep nginx nginx.service disabled 将其配置为自动 ? 1 [root@node142 ~]# systemctl enable nginx.service 查看nginx.service文件 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 [root@node142 ~]# more /lib/systemd/system/nginx.service [Unit] Description=The nginx HTTP and reverse proxy server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=http://www.zzvips.com/run/nginx.pid # Nginx will fail to start if /run/nginx.pid already exists but has the wrong # SELinux context. This might happen when running `nginx -t` from the cmdline. # https://bugzilla.redhat.com/show_bug.cgi?id=1268621 ExecStartPre=http://www.zzvips.com/usr/bin/rm -f /run/nginx.pid ExecStartPre=http://www.zzvips.com/usr/sbin/nginx -t ExecStart=http://www.zzvips.com/usr/sbin/nginx ExecReload=http://www.zzvips.com/bin/kill -s HUP $MAINPID KillSignal=SIGQUIT TimeoutStopSec=5 KillMode=process PrivateTmp=true [Install] WantedBy=multi-user.target 上述配置文件中的内容和官网提供的一模一样 https://www.nginx.com/resources/wiki/start/topics/examples/systemd/ 二、编译安装后的自启动配置 由于是编译安装,短小精悍,二进制位置并记录以便修改启动文件 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 # /u01/app/nginx/sbin/nginx -V nginx version: nginx/1.8.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=http://www.zzvips.com/u01/app/nginx --sbin-path=http://www.zzvips.com/u01/app/nginx/sbin/nginx --conf-path=http://www.zzvips.com/u01/app/nginx/nginx.conf --error-log-path=http://www.zzvips.com/u01/app/nginx/log/error.log --http-log-path=http://www.zzvips.com/u01/app/nginx/log/access.log --pid-path=http://www.zzvips.com/u01/app/nginx/nginx.pid --lock-path=http://www.zzvips.com/u01/app/nginx/nginx.lock --http-client-body-temp-path=http://www.zzvips.com/u01/app/nginx/client_temp --http-proxy-temp-path=http://www.zzvips.com/u01/app/nginx/proxy_temp --http-fastcgi-temp-path=http://www.zzvips.com/u01/app/nginx/fastcgi_temp --http-uwsgi-temp-path=http://www.zzvips.com/u01/app/nginx/uwsgi_temp --http-scgi-temp-path=http://www.zzvips.com/u01/app/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_spdy_module --with-ipv6 下面我们生成一个新的nginx.service文件 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 # vim /lib/systemd/system/nginx.service [Unit] Description=The NGINX HTTP and reverse proxy server After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=http://www.zzvips.com/u01/app/nginx/nginx.pid ExecStartPre=http://www.zzvips.com/u01/app/nginx/sbin/nginx -t ExecStart=http://www.zzvips.com/u01/app/nginx/sbin/nginx ExecReload=http://www.zzvips.com/bin/kill -s HUP $MAINPID ExecStop=http://www.zzvips.com/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target 下面我们先手工停止nginx ? 1 # /u01/app/nginx/sbin/nginx -s stop 配置自启动 ? 1 # systemctl enable nginx.service 使用systemctl工具启动nginx服务 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 # systemctl start nginx.service # systemctl status nginx.service ● nginx.service - The NGINX HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2018-03-29 16:37:47 CST; 6s ago Process: 10588 ExecStart=http://www.zzvips.com/u01/app/nginx/sbin/nginx (code=exited,我们在生产环境基于编译方式安装Nginx后,它开源,很多时候,简单易用, 看下面的例子 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # more /etc/redhat-release CentOS Linux release 7.4.1708 (Core) # ps -ef|grep nginx root 10092 10014 0 16:23 pts/0 00:00:00 grep --color=auto nginx root 20791 1 0 Mar20 ? 00:00:00 nginx: master process ./sbin/nginx -c /u01/app/nginx/nginx.conf nobody 20792 20791 0 Mar20 ? 00:00:44 nginx: worker process nobody 20793 20791 0 Mar20 ? 00:00:42 nginx: worker process nobody 20794 20791 0 Mar20 ? 00:00:50 nginx: worker process nobody 20795 20791 0 Mar20 ? 00:00:44 nginx: worker process nobody 20796 20791 0 Mar20 ? 00:00:43 nginx: worker process nobody 20797 20791 0 Mar20 ? 00:00:43 nginx: worker process nobody 20798 20791 0 Mar20 ? 00:00:37 nginx: worker process nobody 20799 20791 0 Mar20 ? 00:00:48 nginx: worker process nobody 20800 20791 0 Mar20 ? 00:00:04 nginx: cache manager process # 无相应的rpm包,供大家参考,一起跟随小编过来看看吧 Nginx是广为流行的轻量级Web服务器软件, status=0/SUCCESS) Main PID: 10590 (nginx) CGroup: /system.slice/nginx.service ├─10590 nginx: master process /u01/app/nginx/sbin/nginx ├─10591 nginx: worker process # Author : Leshami ├─10592 nginx: worker process # Blog : https://blog.csdn.net/leshami ├─10593 nginx: worker process ├─10594 nginx: worker process ├─10595 nginx: worker process ├─10596 nginx: worker process ├─10597 nginx: worker process ├─10598 nginx: worker process ├─10599 nginx: cache manager process └─10600 nginx: cache loader process Mar 29 16:37:47 ydq-std systemd[1]: Starting The NGINX HTTP and reverse proxy server... Mar 29 16:37:47 ydq-std nginx[10586]: nginx: the configuration file /u01/app/nginx/nginx.conf syntax is ok Mar 29 16:37:47 ydq-std nginx[10586]: nginx: configuration file /u01/app/nginx/nginx.conf test is successful Mar 29 16:37:47 ydq-std systemd[1]: Started The NGINX HTTP and reverse proxy server. ,。

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/server/nginx/12124.shtml

相关文章

风云图片

推荐阅读

返回Nginx频道首页