---
title: "CentOS7搭建OpenResty Nginx"
author: "yang_ch"
date: "2016-04-01T17:34:58Z"
tags: []
categories: ["开源软件"]
slug: "centos7-openresty-nginx"
draft: false
lastmod: "2016-04-01T17:34:58Z"
id: 2288075
url: "https://yang-ch.iteye.com/blog/2288075"
---

下载OpenRestyNginx源码包，按照打包步骤安装，参考文档：

http://openresty.org/cn/installation.html

按照步骤基本都可以正常安装

 

将Nginx加入系统服务：

网上的方法基本都是在/etc/init.d/目录下创建nginx脚本，但是试了好久都不成功。后来看到可以用另外一种SystemCtl的方式加入系统服务，步骤如下：

1.vi /usr/lib/systemd/system/nginx.service,加入脚本

```
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/openresty/nginx/logs/nginx.pid
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t -c /usr/local/openresty/nginx/conf/nginx.conf
ExecStart=/usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
```

 2.启用nginx.service

```
systemctl enable nginx.service
```

 3.systemctl start nginx.service就可以启动项目了，基本不再是service nginx reload了。

 

没有细细研究linux service和systemctl的区别，毕竟不是专业运维，记录下来供后续查资料即可。