nginx、PHP安装配置

1、安装nginx

  sudo apt-get install nginx

  可能会遇见一下错误:

  dpkg: dependency problems prevent configuration of nginx:
  nginx depends on nginx-full (<< 1.14.2-2+deb10u5.1~) | nginx-light (<< 1.14.2-2+deb10u5.1~) | nginx-extras (<< 1.14.2-2+deb10u5.1~); however:
  Package nginx-full is not configured yet.
  Package nginx-light is not installed.
  Package nginx-extras is not installed.
  nginx depends on nginx-full (>= 1.14.2-2+deb10u5) | nginx-light (>= 1.14.2-2+deb10u5) | nginx-extras (>= 1.14.2-2+deb10u5); however:
  Package nginx-full is not configured yet.
  Package nginx-light is not installed.
  Package nginx-extras is not installed.

  解决: 

   1.安装nginx-common:sudo apt-get install nginx-common

  1. 从 /etc/nginx/sites-enabled/default 中删除listen [::]:80 default_server;(我使用 root-user 进行了此操作)

   3.sudo apt-get update,然后是sudo apt-get upgrade

  4.现在我终于调用了sudo apt-get install nginx-full

  

2、配置nginx

  sudo vim /etc/nginx/sites-available/default

  server
  {
    listen 80;               # 443是https的端口,如果你用的是http就用‘80’代替‘443 ssl’
    #server_name webofhu.com;       #此处用你的域名代替webofhu.com
    root /home/demo/myweb;        #此处用网站的位置代替/a/b/c
    index index.php index.html index.htm;

    location ~ \.php$ {
      include fastcgi.conf;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_param PATH_INFO $fastcgi_path_info;
      fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
  }

  切换到/usr/sbin  执行 sudo ./nginx -t 测试配置是否成功

  sudo systemctl restart nginx.service

3、安装PHP

  sudo apt-get install php-fpm

4、配置PHP

  /etc/php/7.3/fpm/pool.d/www.conf

  设置如下:

  ; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect.
  ; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
  ; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
  ; must be separated by a comma. If this value is left blank, connections will be
  ; accepted from any ip address.
  ; Default Value: any
  listen = 127.0.0.1:9000
  listen.allowed_clients = 127.0.0.1

 

posted @ 2023-04-14 21:03  *^VV^*  阅读(74)  评论(0编辑  收藏  举报