linux文件目录
1  | / - 根  | 
linux搭建环境
nginx配置
1、运行以下命令查看Nginx配置文件的默认路径
1  | cat /etc/nginx/nginx.conf  | 
2、进入对应目录
1  | cd /etc/nginx/conf.d // 进入相关目录  | 
3、运行一下命令打开默认配置文件
1  | vi default.conf // 编辑配置文件  | 
4、按i进入编辑模式。
5、在location大括号内,修改以下内容。
1  | location / {  | 
6、去掉被注释的location ~ \.php$大括号内容前的#,并修改大括号的内容。
修改完成如下所示。1
2
3
4
5
6
7
8
9
10
11location ~ \.php$ {
    #将该路径替换为您的网站根目录。
    root           /usr/share/nginx/html;
    #Nginx通过unix套接字与PHP-FPM建立联系,该配置与/etc/php-fpm.d/www.conf文件内的listen配置一致。
    fastcgi_pass   unix:/run/php-fpm/www.sock;
    fastcgi_index  index.php;
    #将/scripts$fastcgi_script_name修改为$document_root$fastcgi_script_name。
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    #Nginx调用fastcgi接口处理PHP请求。
    include        fastcgi_params;
}
7、按下esc,并输入:wq保存退出文件
8、运行以下命令启动Nginx服务。
1  | systemctl start nginx  | 
9、运行以下命令设置Nginx服务开机自启动。
1  | systemctl enable nginx  |