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

编译、安装
[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(服务重载)

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

猜你喜欢

转载自blog.csdn.net/weixin_43328213/article/details/87801094