Nginx服务的搭建与配置

    科技2026-02-12  3

    1.系统环境 操作系统:centos 7

    2.关闭selinux 修改配置selinux的配置文件 #vim /etc/selinux/config 将内容中的SELINUX=enforcing修改为SELINUX=disable #setenforce 0 #reboot #sestatus

    3.关闭防火墙 #systemctl stop firewalld #systemctl disable firewalld

    4.安装epel源 #yum -y install epel-release

    5.安装Nginx,php-fpm #yum -y install nginx #yum -y install php-fpm #vim /etc/php-fpm.d/www.conf //修改配置文件 :/apache user = nginx //注意空格 group = nginx

    6.启动Nginx并设置开机自动运行 #systemctl start nginx #systemctl enable nginx

    7、修改配置文件

    #vim /etc/nginx/conf.d/admin.conf //添加以下内容 server{ listen 80; //端口 server_name www.test.com admin.test.com ; //域名 root /var/www/card/public; //网站根目录 index index.php index.html index.htm; location / { if (!-e KaTeX parse error: Expected '}', got 'EOF' at end of input: …{ rewrite ^(.*) /index.php?s=/KaTeX parse error: Expected 'EOF', got '}' at position 41: …dex.php break; }̲ } Location ~ \… { #root /var/www/card/public; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME d o c u m e n t r o o t document_root documentrootfastcgi_script_name; include fastcgi_params; } }

    #cd /var/www/ #mkdir -p card/public #cd card/ #cd public/ #vim php_info.php

    <?php echo "hello world; ?> #systemctl restart php-fpm

    8、测试 现在把服务关闭: #systemctl stop php-fpm #lsof -i:9000

    Processed: 0.083, SQL: 10