lnmp---nginx的源码安装与配置

79 篇文章 0 订阅
编译、安装
[root@server1 ~]# ls
           nginx-1.14.0.tar.gz
[root@server1 ~]# tar zxf nginx-1.14.0.tar.gz (解压安装包)
[root@server1 ~]# cd nginx-1.14.0
[root@server1 nginx-1.14.0]# vim src/core/nginx.h
	 14 #define NGINX_VER          "nginx/" (删除版本号,防止被攻击)
[root@server1 nginx-1.14.0]# vim auto/cc/gcc 
	171 # debug
	172 #CFLAGS="$CFLAGS -g"(屏蔽debug日志,因其日志太多,占用内存,一般出错后,可打开查看日志)

[root@server1 nginx-1.14.0]# ./configure --prefix=/usr/local/lnmp/nginx
 --with-http_ssl_module --with-http_stub_status_module --with-threads 
 --with-file-aio --user=nginx --group=nginx

源码编译报错,需要pcre,安装pcre-devel.
在这里插入图片描述
再次编译成功

[root@server1 nginx-1.14.0]# ./configure --prefix=/usr/local/lnmp/nginx 
--with-http_ssl_module --with-http_stub_status_module --with-threads 
--with-file-aio --user=nginx --group=nginx
[root@server1 nginx-1.14.0]# make && make install
配置
[root@server1 nginx-1.14.0]# cd /usr/local/lnmp/
[root@server1 lnmp]# cd nginx/
[root@server1 nginx]# ls
conf  html  logs  sbin
[root@server1 nginx]# cd conf/
[root@server1 conf]# vim nginx.conf
 43         location / {
 44             root   html;
 45             index  index.php index.html index.htm;(添加了index.php,可访问动态网页)
 46         }

 65         location ~ \.php$ {
 66             root           html;
 67             fastcgi_pass   127.0.0.1:9000;
 68             fastcgi_index  index.php;
 69         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
70             include        fastcgi.conf;  
 71         }

[root@server1 conf]# cd ../sbin/
[root@server1 sbin]# ./nginx -t(语法检测)
[root@server1 sbin]# ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/(为方便使用服务,做一个软链接)
[root@server1 sbin]# nginx (开启nginx)	
[root@server1 sbin]# netstat -lntp
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      25412/nginx  

查看nginx服务端口,我们可以看到其端口与httpd默认端口相同,因此只能打开一项服务,或者修改httpd的端口号,在/etc/httpd/conf/httpd.conf文件修改

访问网页成功
在这里插入图片描述
编辑一个php网页文件

[root@server1 sbin]# cd /usr/local/lnmp/nginx/html/
[root@server1 html]# vim index.php
	<?php
	phpinfo()
	?>
[root@server1 html]# nginx -s reload(服务重载)

访问成功
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值