`
小于Brick
  • 浏览: 88927 次
  • 性别: Icon_minigender_1
  • 来自: 新疆
社区版块
存档分类
最新评论

centos7 nginx 开机自启动

阅读更多

参考:

http://www.centoscn.com/CentOS/config/2015/0507/5374.html

 

vi添加nginx.service

[root@klmy-460-res01 ~]# vi /usr/lib/systemd/system/nginx.service

编辑nginx.service内容

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx      
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop                  
PrivateTmp=true

[Install]
WantedBy=multi-user.target 

 

应用nginx自启动服务:

[root@klmy-460-res01 ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

 

开启服务:

[root@klmy-460-res01 ~]# systemctl start nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

有错误,没有开启成功。

 

 查看服务状态:

[root@klmy-460-res01 ~]# systemctl status nginx
● nginx.service - nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 五 2016-12-16 17:25:07 CST; 3min 55s ago
  Process: 34804 ExecStart=/usr/etc/ngin/sbin/nginx (code=exited, status=1/FAILURE)

12月 16 17:25:05 klmy-460-res01 nginx[34804]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
12月 16 17:25:05 klmy-460-res01 nginx[34804]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
12月 16 17:25:06 klmy-460-res01 nginx[34804]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
12月 16 17:25:06 klmy-460-res01 nginx[34804]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
12月 16 17:25:07 klmy-460-res01 nginx[34804]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
12月 16 17:25:07 klmy-460-res01 nginx[34804]: nginx: [emerg] still could not bind()
12月 16 17:25:07 klmy-460-res01 systemd[1]: nginx.service: control process exited, code=exited status=1
12月 16 17:25:07 klmy-460-res01 systemd[1]: Failed to start nginx.
12月 16 17:25:07 klmy-460-res01 systemd[1]: Unit nginx.service entered failed state.
12月 16 17:25:07 klmy-460-res01 systemd[1]: nginx.service failed.

状态信息为,端口占用。

 

关闭已启动的nginx

[root@klmy-460-res01 ~]# /usr/etc/ngin/sbin/nginx -s stop

 

重新执行systemctl start命令开启服务:

[root@klmy-460-res01 ~]# systemctl start nginx
[root@klmy-460-res01 ~]# systemctl status nginx
● nginx.service - nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since 五 2016-12-16 17:32:58 CST; 17s ago
  Process: 34825 ExecStart=/usr/etc/ngin/sbin/nginx (code=exited, status=0/SUCCESS)
 Main PID: 34826 (nginx)
   CGroup: /system.slice/nginx.service
           ├─34826 nginx: master process /usr/etc/ngin/sbin/nginx
           └─34827 nginx: worker process

12月 16 17:32:58 klmy-460-res01.klmyedu.cn systemd[1]: Starting nginx...
12月 16 17:32:58 klmy-460-res01.klmyedu.cn systemd[1]: Started nginx.

 

重启服务器:

[root@klmy-460-res01 ~]# reboot

 

测试是否已经启动了

windows 命令行:

telnet 服务器ip 端口

 看到黑屏光标闪烁为已经启动

 

 

 

 

分享到:
评论

相关推荐

    nginx.service——nginx开机自启动配置文件[CentOS 7.6 64位]

    nginx开机自启动配置文件,在[CentOS 7.6 64位]系统下运行正常。 编译安装nginx后,将该配置文件放在服务器的/usr/lib/systemd/system/目录下,然后启动nginx服务。

    CentOS 8 开机启动Nginx脚本

    CentOS 8 开机启动Nginx脚本

    详解Centos7中Nginx开机自启动的解决办法

    关于在centos7中设置Nginx开机自启动,我们可以通过编写开机自启动shell脚本来解决。 测试环境 操作系统:centos7 64位 1611 Nginx版本: 1.11.10 本机Nginx安装时的配置参数 ./configure \ --prefix=/usr/...

    centos7系统下nginx安装并配置开机自启动操作

    至此,Nginx已经在CentOS7系统上成功安装并配置为开机自启动。当系统重启时,Nginx服务会自动启动,为你的Web应用程序提供服务。如果需要调整Nginx的配置,只需编辑`/usr/local/nginx/conf/nginx.conf`文件,并使用`...

    在Linux操作系统中通过systemctl设置nginx开机自动启动步骤

    在Linux操作系统中,管理服务的常用工具是`systemd`,它允许系统管理员控制服务的启动、停止、重启以及设置开机自启动。针对Nginx这种常见的Web服务器,确保其在服务器重启后能够自动启动是非常重要的,可以避免服务...

    centos安装Nginx详细配置

    ### CentOS安装Nginx详细配置知识点 #### 一、安装准备 在开始部署Nginx之前,需要确保系统中已安装必要的开发工具和依赖库。 ##### 1. 安装GCC - **简介**:GCC (GNU Compiler Collection) 是一个用于编译多种...

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

    本文将详细介绍如何在基于CentOS 7的环境中配置Nginx服务器实现自启动功能。Nginx作为轻量级Web服务器,在开源领域备受欢迎,以其高效、简单易用的特性深受互联网企业和IT运维人员的喜爱。尤其在生产环境中,Nginx...

    centos7下安装nginx(有网以及没有网络)

    3. **启动 Nginx 并设置开机自启** ```bash sudo systemctl start nginx sudo systemctl enable nginx ``` 4. **验证安装** 打开浏览器访问 `http://your_server_ip`,应该能看到 Nginx 的默认欢迎页面。 ###...

    linux Nginx源码编译安装以及开机启动设置(CentOS6.3)

    本文将详细介绍如何在CentOS 6.3上通过源码编译安装Nginx,并设置其为开机启动。 一、准备工作 在开始安装前,确保系统已经更新到最新版本,并安装了必要的依赖工具。运行以下命令: ```bash sudo yum update -y ...

    centos7安装nginx1.16.1

    #### 七、设置开机自启动 为了让 Nginx 在系统启动时自动运行,需要在 `/etc/rc.local` 文件中添加启动代码: ```bash vi /etc/rc.local ``` 在文件末尾添加以下行: ```bash /usr/local/nginx/sbin/nginx ``` ...

    Centos7.9 离线安装Nginx依赖包

    6. 启动Nginx服务:使用`systemctl start nginx`命令启动,如果需要开机自启,使用`systemctl enable nginx`。 7. 验证Nginx运行状态:使用`systemctl status nginx`检查Nginx服务是否正常运行。 离线安装Nginx在...

    centos/rhel下实现nginx自启动脚本实例

    在CentOS/RHEL操作系统中,为了确保Nginx web服务器在系统启动时自动运行,我们需要创建一个自启动脚本,并将其添加到系统的服务管理中。这个脚本将处理启动、停止、重启和重新加载Nginx配置等操作。下面详细解释...

    CentOS7-Nginx安装包(相关所有依赖包).zip

    6. 设置Nginx开机启动: ``` systemctl enable nginx ``` 7. 验证Nginx是否正确运行,可以访问服务器的IP地址或主机名,如果看到Nginx的默认欢迎页面,说明安装成功。 在实际应用中,我们可能还需要对Nginx进行...

    Linux配置nginx自启动

    Linux配置Nginx服务开机自启动(centos7.*配置方式不同),脚本中‘nginx=‘和‘NGINX_CONF_FILE=’后面的*****替换成自己的nginx安装路径。把脚本复制到init.d/目录下,添加chkconfig --add nginx即可。注意脚本的...

    centos7 Nginx离线所有资源包

    7. **设置开机启动**:为了确保系统重启后Nginx能自动启动,执行以下命令: ```bash sudo systemctl enable nginx ``` 至此,Nginx已在CentOS 7系统上离线安装成功。你可以通过访问服务器的IP地址或域名来测试...

    CentOS自动安装nginx

    5. **设置开机启动**:使用`sudo systemctl enable nginx`让Nginx在系统启动时自动启动。 6. **配置防火墙**:如果使用的是firewalld,运行`sudo firewall-cmd --permanent --add-service=http`和`sudo firewall-...

    CentOS6 配置Nginx,MySql,php-fpm开机启动的方法

    本文将详细介绍如何在CentOS 6上配置Nginx、MySQL和php-fpm这三个关键组件以实现开机自启。 首先,我们来看Nginx的配置步骤: 1. 在`/etc/init.d/`目录下创建一个名为`nginx`的启动脚本。使用`vim`编辑器创建这个...

    Centos7安装Nginx或OpenResty1

    总结,本文详细介绍了如何在 CentOS7 系统上安装 Nginx,包括安装依赖、编译安装、启动管理以及设置开机自启。理解并掌握这些步骤对于任何希望在 CentOS7 上部署 Nginx 的开发者都是至关重要的。对于 OpenResty 的...

    centOS8安装nginx及nginx配置

    2. **设置开机自启**: ```bash systemctl enable nginx ``` 3. **启动Nginx服务**: ```bash systemctl start nginx ``` 4. **查看状态**: ```bash systemctl status nginx ``` 5. **重启服务**: ``...

Global site tag (gtag.js) - Google Analytics