CentOS 7 nginx安装

1.下载nginx

http://nginx.org/en/download.html

http://nginx.org/download/nginx-1.13.3.tar.gz

[root@centos]# wget http://nginx.org/download/nginx-1.13.3.tar.gz

2.解压nginx到 /tmp 目录下

[root@centos]# tar -zxvf nginx-1.13.3.tar.gz
[root@centos]# cd nginx-1.13.3

3.编译安装nginx

[root@centos]# ./configure
[root@centos]# make && make install
[root@centos]# whereis nginx

4.在/usr/lib/systemd/system/目录下创建nginx.service

[root@centos]# vim /usr/lib/systemd/system/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 quit
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

更改文件权限

[root@centos]# chmod 745 /usr/lib/systemd/system/nginx.service

常用命令

[root@centos]# systemctl enable nginx.service   # 设置开机自启动
[root@centos]# systemctl start nginx.service    # 启动服务
[root@centos]# systemctl stop nginx.service     # 停止服务
[root@centos]# systemctl restart nginx.service  # 重启服务
[root@centos]# systemctl status nginx.service   # 检查状态

ps: 如果出现没有权限在 conf 文件开头加上 use root;

use root;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容