nginx编译安装

nginx编译安装

1.nginx安装方式

yum:       导入nginx源
编译安装:   下载源码包,编译安装

1)yum安装方式:

nginx源配置:http://nginx.org/en/linux_packages.html#stable

安装的版本和模块以及路径等等

打开浏览器输入自己的IP地址即可

2)编译安装方式

安装依赖的包

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel prce prce-devel -y

[root@Cassandra ~]# groupadd nginx
[root@Cassandra ~]# useradd -r -g nginx -s /bin/nologin -M nginx

[root@Cassandra src]# wget http://nginx.org/download/nginx-1.12.1.tar.gz
[root@Cassandra src]# pwd
/usr/local/src
[root@Cassandra src]# ls
nginx-1.12.1.tar.gz

解压安装

[root@Cassandra src]# tar  xf nginx-1.12.1.tar.gz 
[root@Cassandra src]# cd nginx-1.12.1/
./configure 
--prefix=/usr/local/nginx                             #安装的目录
--sbin-path=/usr/sbin/nginx                           #nginx启动目录
--conf-path=/etc/nginx/nginx.conf                     #主配置文件路径
--error-log-path=/var/log/nginx/error.log             #错误日志
--http-log-path=/var/log/nginx/access.log             #访问日志
--pid-path=/var/run/nginx/nginx.pid                   #pid文件
--lock-path=/var/lock/nginx.lock                      #锁文件位置
--user=nginx                                          #用户
--group=nginx                                         #用户组
--with-http_ssl_module                                #ssl 模块
--with-http_flv_module                                #启动流媒体播放模块
--with-http_stub_status_module                        #状态模块,监控要用到
--with-http_gzip_static_module                        #解压模块
--http-client-body-temp-path=/var/tmp/nginx/client/   #客户端请求报文临时存储位置
--http-proxy-temp-path=/var/tmp/nginx/proxy/          #代理模块的缓存目录
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/         #fastcgi的缓存目录
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi           #uwsgi的缓存目录
--http-scgi-temp-path=/var/tmp/nginx/scgi             #scgi的缓存目录
--with-pcre                                           #支持pcre的功能
./configure --prefix=/usr/local/nginx  --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log  --pid-path=/var/run/nginx/nginx.pid  --lock-path=/var/lock/nginx.lock  --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module  --with-http_gzip_static_module  --http-client-body-temp-path=/var/tmp/nginx/client/  --http-proxy-temp-path=/var/tmp/nginx/proxy/  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/  --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi  --http-scgi-temp-path=/var/tmp/nginx/scgi  --with-pcre
make && make install
遇到错误:

[root@Cassandra nginx-1.12.1]# /usr/sbin/nginx
 nginx: [emerg] mkdir() "/var/tmp/nginx/client/" failed (2: No such file or directory)
[root@Cassandra nginx-1.12.1]# mkdir -p /var/tmp/nginx/client/

# /usr/sbin/nginx                     #启动nginx服务
# netstat -tanp | grep nginx          #查看nginx端口
# ps -ef | grep nginx                 #查看nginx进程
# kill -9 [nginx的进程号]              #停止nginx服务
编写systemd启动
进入/usr/lib/systemd/system
vim nginx.service

[Unit]
Description=nginx
After=network.target

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

[Install]
WantedBy=multi-user.target

chmod +x nginx.service

启动测试执行,多验证几遍,以上都是自己的个人的总结,如有错误,欢迎大家指正。

posted @ 2017-08-09 11:34  Cassandrahan  阅读(259)  评论(0)    收藏  举报