centos7 安装nginx

yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel -y

 

wget  http://nginx.org/download/nginx-1.6.3.tar.gz
tar -zxvf nginx-1.6.3.tar.gz

cd nginx-1.6.3

./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --pid-path=/usr/local/nginx/conf/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgi --with-http_stub_status_module --with-http_ssl_module

make && make install
whereis nginx
cd /usr/local/nginx/sbin/

 ./nginx(如果出现下面报错)

 mkdir -p /var/temp/nginx 
./nginx

netstat -anput

开机自启动

在系统服务目录里创建nginx.service文件

vi /lib/systemd/system/nginx.service

内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
[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

[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3

保存退出。

2.设置开机启动

1
systemctl enable nginx.service

3.其他命令

启动nginx服务

设置开机自启动

停止开机自启动

查看服务当前状态

重新启动服务

查看所有已启动的服务

原文地址:https://www.cnblogs.com/guarderming/p/10443748.html