开发者社区> 问答> 正文

Centos7手工配置lnmp环境之一:Nginx篇

继上一教程已相当久远了,本不打算更新了,因为手工配置实在麻烦,但自己刨了个坑,没有办法。所以还是继续更新吧!
上篇地址:Centos7手工配置lnmp环境之一:Mysql篇
开始今天的教程!
一、准备工作
1.1.安装一些组件和库
yum -y install gcc wget automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel zlib
1.2.下载nginx
访问nginx的官方网站 http://nginx.org/ 下载最新的稳定版本
cd /root/lnamp
wget http://nginx.org/download/nginx-1.10.1.tar.gz

二、安装nginx
2.1.先创建用户和用户组
groupadd www
useradd -g www www -s /bin/false

2.2. 创建一个nginx目录用来存放运行的临时文件夹
mkdir -p /var/cache/nginx
2.3.开始安装nginx
2.3.1.解压nginx
cd /root/lnamp
tar zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1


2.3.2.进行configure
./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.pid \--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \--user=nobody \
--group=nobody \--with-pcre \
--with-http_v2_module \--with-http_ssl_module \
--with-http_realip_module \--with-http_addition_module \
--with-http_sub_module \--with-http_dav_module \
--with-http_flv_module \--with-http_mp4_module \
--with-http_gunzip_module \--with-http_gzip_static_module \
--with-http_random_index_module \--with-http_secure_link_module \
--with-http_stub_status_module \--with-http_auth_request_module \
--with-mail \--with-mail_ssl_module \
--with-file-aio \--with-ipv6 \
--with-http_v2_module \--with-threads \
--with-stream \--with-stream_ssl_module

2.3.3.make && make install
make && make install
以上过程中如果无错,那就是安装好了,如果有错误,大家贴在下面我来解决,主要是我编译过程中没有出错。
2.4.启动nginx
/usr/sbin/nginx
2.5.用ps aux来查看nginx是否启动 ps aux|grep nginx

2.6.然后配置服务 vim /usr/lib/systemd/system/nginx.service

  按"i"输入以下内容 [Unit]
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=/var/run/nginx.pidExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.confExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPIDPrivateTmp=true

[Install]
WantedBy=multi-user.target

    编辑好后保存
:wq!
2.7.然后开启开机启动
systemctl enable nginx.service
2.8.测试配置文件
用命令关掉nginx
pkill -9 nginx
后面可以用systemctl来操作nginx.service
systemctl start nginx.service
可以看到已启动成功
访问ip会看到nginx的启动画面
[attachment=107103]

文中其实有许多图片的,编辑好了再补!

展开
收起
鬼才神兵 2016-07-31 22:47:29 5181 0
4 条回答
写回答
取消 提交回答
  • ReCentos7手工配置lnmp环境之一:Nginx篇
    楼主你好,我编辑vim /usr/lib/systemd/system/nginx.service这个保存的时候提示文件不存在,该怎么处理呢
    2016-08-03 14:14:20
    赞同 展开评论 打赏
  • 阿里云论坛版主,伪Linux运维,完美主义者。
    回 2楼(linanxiaoxiao) 的帖子
    管理不给个精华啥的?

    -------------------------

    回 4楼(耘升) 的帖子
    那个文件本身不存在,是新建,然后复制内容进去!
    2016-08-01 12:10:56
    赞同 展开评论 打赏
  • 云栖社区聚能聊、问答管理员~发福利、搞怪,八卦我来,论技术、发话题、写博客你上!
    楼主加油哦~
    2016-08-01 10:03:40
    赞同 展开评论 打赏
  • 码农|Coder| Pythonista
    看起来不错!
    2016-08-01 08:14:51
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
《Nginx 代理系统常用手册》 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载