搭建lnmp环境-nginx

发布时间 2023-12-19 17:35:27作者: 猫猫客服

nginx无所谓版本了

需要指定版本的话,需要配置nginx源,再继续。

# 安装

yum -y install nginx 

# 启动

systemctl start nginx

 

设置开机自启动:

systemctl enable nginx.service
查看是否正确启动:

systemctl list-unit-files |grep nginx

看下如下图就成功启动了

 

安装php扩展 php-fpm

yum -y install php-fpm

设置开机重启

systemctl enable php-fpm.service

 

 这里我修改成www用户和www用户组,后面给www配置权限方便,原来的那个没办法配置权限。

新增用户www,查看用户的用户组

groups <用户名>
修改后,重启php-fpm
systemctl restart php-fpm.service


需要关闭防火墙!才能访问,或者开放端口。
server {
    listen 8080;
    server_name  192.168.2.128;

    root   /usr/share/nginx/html/test1;
   
    location / {        
        index index.php index.html index.htm;
        if (!-e $request_filename) {
          rewrite  ^(.*)$  /index.php?s=/$1  last;
          break;
        }
    }
   
    location ~ \.(php|phar)(/.*)?$ {
      fastcgi_split_path_info  ^(.+\.(?:php|phar))(/.*)$;
      fastcgi_intercept_errors on;
      fastcgi_index index.php;
      include   fastcgi_params;
      fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      fastcgi_param PATH_INFO $fastcgi_path_info;
      fastcgi_pass  127.0.0.1:9000;
    }
}