nginx配置php-fpm虚拟主机站点

ubuntu下安装nginx 很简单 sudo apt-get install nginx

然后安装php-fpm 我这本地php7.4所以这么写

sudo apt search php7.4-fpm

然后好了以后改一下配置 /etc/php/7.4/fpm/pool.d里面找到 listen

;listen = /run/php/php7.4-fpm.sock
listen = 127.0.0.1:9000

分号注释上面的 添加开启下面的

然后把那些php ini需要开的扩展都在 /etc/php/7.4/fpm/php.ini里面给开起来

重启php-fpm服务

sudo /etc/init.d/php7.4-fpm restart

看看它现在状态

$ netstat -tln |grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN 

发现已经监听了端口

$ sudo systemctl status php7.4-fpm
● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-02-18 13:42:21 +08; 8min ago
       Docs: man:php-fpm7.4(8)
    Process: 725830 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/7.4/fpm/pool.d/www.conf 74 (c>
   Main PID: 725826 (php-fpm7.4)
     Status: "Processes active: 0, idle: 2, Requests: 2, slow: 0, Traffic: 0req/sec"
      Tasks: 3 (limit: 18996)
     Memory: 16.9M
     CGroup: /system.slice/php7.4-fpm.service
             ├─725826 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
             ├─725828 php-fpm: pool www
             └─725829 php-fpm: pool www

2月 18 13:42:21 cit000174nb systemd[1]: Starting The PHP 7.4 FastCGI Process Manager...
2月 18 13:42:21 cit000174nb systemd[1]: Started The PHP 7.4 FastCGI Process Manager.

并且php-fpm的状态运行良好

然后去做nginx的配置 创建一个站点文件

/etc/nginx/sites-available/local.ice.com

编辑内容为

#Log Format
  log_format access_exp '$time_iso8601 | $remote_addr | $request | $status | $request_body | $http_referer | $http_user_agent | $http_x_forwarded_for';

server {
  listen 80;

  root /var/www/html/ice/hello/public;

  index index.html index.htm index.php ;
  server_name local.ice.com;

  # log
  access_log /var/log/nginx/local.ice.com.access.log access_exp;
  error_log /var/log/nginx/local.ice.com.error.log;

  location ~ \.php$ {
    root           /var/www/html/ice/hello/public;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
  }
}

然后来到/etc/nginx/sites-enabled

进行设置一个软链接文件

sudo ln -s ../sites-available/local.ice.com local.ice.com

然后查看一下ls -al

$ ls -al
total 16
drwxr-xr-x 2 root root 4096 2月  18 11:28 ./
drwxr-xr-x 8 root root 4096 6月   7  2021 ../
-rw-r--r-- 1 root root 2416 3月  26  2020 default
-rw-rw-rw- 1 root root  677 2月  18 13:35 local.ice.com

然后就 重启nginx

sudo systemctl restart nginx.service

如果你只想重启nginx配置可以使用

nginx -s reload

如果遇到这个提示

nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
nginx: [alert] kill(728201, 1) failed (1: Operation not permitted)

加sudo就行了  sudo nginx -s reload 

启动后看看/var/log/nginx/local.ice.com.error.log 和 /var/log/nginx/local.ice.com.access.log

如果有啥错误就按照错误提示去改就行了

posted @ 2022-02-18 13:59  李照耀  阅读(498)  评论(0编辑  收藏  举报