一、环境准备
[root@Server ~]# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)
[root@Server ~]# uname -r
3.10.0-957.10.1.el7.x86_64
二、增加Nginx源
#vi /etc/yum.repos.d/Nginx.repo
源的内容
[Nginx]
name=Nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
查看源是否配置成功
yum list Nginx
yum list |grep Nginx
三、下载lnmp软件包
安装lnmp服务
yum install -y Nginx mariadb-server PHP-MysqL PHP-fpm
启动lnmp服务
systemctl start Nginx.service mariadb.service PHP-fpm.service
加入开机启动
systemctl enable Nginx.service mariadb.service PHP-fpm.service
检查是否启动
[root@Server ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:9000 0.0.0.0: LISTEN 15807/PHP-fpm: mast
tcp 0 0 0.0.0.0:3306 0.0.0.0: LISTEN 16056/MysqLd
tcp 0 0 0.0.0.0:80 0.0.0.0: LISTEN 15811/Nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0: LISTEN 6583/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0: LISTEN 7105/master
tcp6 0 0 :::22 ::: LISTEN 6583/sshd
tcp6 0 0 ::1:25 ::: LISTEN 7105/master
udp 0 0 127.0.0.1:323 0.0.0.0: 6066/chronyd
udp6 0 0 ::1:323 :::* 6066/chronyd
四、编写Nginx配置文件
vi /etc/Nginx/Nginx.conf
[root@Server ~]# cat /etc/Nginx/Nginx.conf
user Nginx;
worker_processes 1;
error_log /var/log/Nginx/error.log warn;
pid /var/run/Nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/Nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/Nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.PHP index.html index.htm;
}
location ~ \.PHP$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
include /etc/Nginx/conf.d/*.conf;
}
重启Nginx服务
systemctl restart Nginx.service
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。