说明:
- 服务器:腾讯云Linux服务器
- Linux:CentOS 7.6
- Nginx:Nginx 1.17.7
安装 Nginx
- 执行以下命令,在
/etc/yum.repos.d/
下创建nginx.repo
文件。vi /etc/yum.repos.d/nginx.repo
- 按 i 切换至编辑模式,写入以下内容。
[nginx] name = nginx repo baseurl = https://nginx.org/packages/mainline/centos/7/$basearch/ gpgcheck = 0 enabled = 1
- 按 Esc,输入 :wq,保存文件并返回。
- 执行以下命令,安装 nginx。
yum install -y nginx
- 执行以下命令,打开
default.conf
文件。vim /etc/nginx/conf.d/default.conf
- 按 i 切换至编辑模式,编辑
default.conf
文件。 - 找到
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; } }
- 按 Esc,输入 :wq,保存文件并返回。
- 执行以下命令启动 Nginx。
systemctl start nginx
- 执行以下命令,设置 Nginx 为开机自启动。
systemctl enable nginx
- 在本地浏览器中访问以下地址,查看 Nginx 服务是否正常运行。
http://云服务器实例的公网 IP
显示如下,则说明 Nginx 安装配置成功。
版权声明:本文为zdc1228原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。