花花世界蕾 发表于 2017-12-22 21:36:49

nginx (lnmp)配置支持php,虚拟主机

  实验环境:RHEL7
  安装方式:yum
  配置lnmp
  1.安装lnmp
  yum install -y php-mysqlmariadb mariadb-serverphp-fpm php*
  2.配置防火墙:firewall-cmd --permanent --add-service=http&& firewall-cmd--reload
  3.设置nginx和php-fpm 开机自启:systemctl enablenginx php-fpm &&systemctl restart   nginx php-fpm
  4.配置nginx支持php, 打开 vim /etc/nginx/conf.d/default.conf 开启以下注解:
  location ~ \.php$ {
  root html;
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_indexindex.php;
  fastcgi_paramSCRIPT_FILENAME/usr/share/nginx/html$fastcgi_script_name;
  include      fastcgi_params;
  }
  5.在nginx的Document目录(/usr/share/nginx/html)创建test.php测试页
  vim /usr/share/nginx/html/test.php
  <?php
  phpinfo();
  ?>
  :wq
  重启nginx :systemctl restart   nginx
  (ifconfig)访问服务器ip地址
  nginx虚拟主机    注意! 虚拟主机配置文件需要分开写!!还需注意虚拟主机Document目录的selinux的设置!
  1.vim /etc/nginx.conf
  找到虚拟主机文件的配置路径:include /etc/nginx/conf.d/*.conf;
  2.在include /etc/nginx/conf.d/*.conf目录下创建虚拟主机配置文件。
  例子:
  server {
  listen 80;                                       #监听端口
  server_name www.example.com;       #主机名
  location / {
  root /var/www/nginx1-html;            #虚拟主机Document目录
  index index.html index.htm;               #主页文件名
  }
  }
  支持php的虚拟主机 vim   /etc/nginx/conf.d/virt-php.conf:
  server {
  listen 80;
  server_name club2.example.com;
  location / {
  root /var/www/nginx1-html;
  index index.html index.htm;
  }
  location ~ \.php$ {
  root html;
  fastcgi_pass 127.0.0.1:9000;
  fastcgi_indexindex.php;
  fastcgi_paramSCRIPT_FILENAME /var/www/nginx1-html$fastcgi_script_name;
  include      fastcgi_params;
  }
  }
页: [1]
查看完整版本: nginx (lnmp)配置支持php,虚拟主机