linux:nginx

nginx介绍

 一个web服务器软件,类似于Apache。

排名:链接

源码包安装

下载

下载地址:链接

在服务器端下载:wget 地址

将nginx下载到 /usr/local/src:

wget   http://nginx.org/download/nginx-1.19.0.tar.gz     

查看:

解压

tar -zxvf nginx-1.19.0.tar.gz

进入解压目录查看:

配置

 ./configure  --prefix=/usr/local/nginx

出错:没有PCRE库

解决方法:直接yum安装pcre-devel

yum install pcre-level

安装完成:

再次尝试:

 ./configure  --prefix=/usr/local/nginx --with-pcre

再次报错:没有zlib库

解决方法:直接yum安装zlib库,并将zlib库下载后解压

yum install zlib-devel

安装完成:

下载zlib库并解压:

wget http://www.zlib.net/zlib-1.2.11.tar.gz

解压后查看:

 tar -zxvf zlib-1.2.11.tar.gz

再次尝试:

./configure  --prefix=/usr/local/nginx --with-pcre  --with-zlib=/usr/local/src/zlib-1.2.11

编译

make

安装

make install

安装完成的目录:

改端口

运行

由于nginx也占用端口8080,故先停止Apache,再运行nginx:

nginx启动:

/usr/local/nginx/sbin/nginx 

nginx重启:

/usr/local/nginx/sbin/nginx -s reload

nginx关闭:

查看端口:

netstat -tnlp

kill该进程:

kill 17005

yum安装

下载

1、在 /etc/yum.repos.d/ 下创建 nginx.repo 文件

vi /etc/yum.repos.d/nginx.repo

2、按 “i” 切换至编辑模式,写入以下内容

[nginx] 
name = nginx repo 
baseurl = https://nginx.org/packages/mainline/centos/7/$basearch/ 
gpgcheck = 0 
enabled = 1

3、按 “Esc”,输入 “:x”,保存文件并返回

安装 

yum install -y nginx

编辑

1、打开 nginx.conf 文件

vim /etc/nginx/nginx.conf

2、按 “i” 切换至编辑模式,编辑 nginx.conf 文件

3、找到 server{...},并将 server 大括号中相应的配置信息替换为如下内容。用于取消对 IPv6 地址的监听,同时配置 Nginx,实现与 PHP 的联动。

server {
 listen       80;
 root   /usr/share/nginx/html;
 server_name  localhost;
 #charset koi8-r;
 #access_log  /var/log/nginx/log/host.access.log  main;
 #
 location / {
       index index.php index.html index.htm;
 }
 #error_page  404              /404.html;
 #redirect server error pages to the static page /50x.html
 #
 error_page   500 502 503 504  /50x.html;
 location = /50x.html {
   root   /usr/share/nginx/html;
 }
 #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 #
 location ~ .php$ {
   fastcgi_pass   127.0.0.1:9000;
   fastcgi_index  index.php;
   fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
   include        fastcgi_params;
 }
}

若 nginx.conf 文件中未找到 server{...},请在 include /etc/nginx/conf.d/*conf;上方添加以上的 server{...} 配置内容

按 “Esc”,输入 “:x”,保存文件并返回

启动 

systemctl start nginx

设置为开机自启动

systemctl enable nginx

测试

http://云服务器实例的公网 IP

 
原文地址:https://www.cnblogs.com/pam-sh/p/13086847.html