nginx、PHP安装配置

发布时间 2023-04-14 21:07:42作者: *^VV^*

1、安装nginx

  sudo apt-get install nginx

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