🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 包管理器快速部署LNMP环境 使用包管理快部署LNMP环境,其实和LAMP服务器环境是一样的,LAMP使用nginx提供web服务,而LAMP使用apache提供web服务。PHP和mysql的安装和LAMP的是一样的,在这里就不做详细的介绍了。 在本节重点介绍一下nginx的安装和配置。 ### 1. nginx的安装 ~~~ yum install -y nginx ~~~ ### 2. 启动nginx ~~~ service nginx start ~~~ ### 3. 测试 nginx安装好后会自动生成默认站点,默认站点路径usr/share/nginx/html ~~~ http://服务器IP ~~~ ### 4. 创建自定义站(多站点) nginx 安装好之后,配置文件目录为:/etc/nginx 域名:www.test.com 将域名解析到服务器IP 创建站点目录:/var/www/html 创建index.html:/var/www/html/index.html 创建测试站点配置文件 /etc/nginx/conf.d/test.com.conf ,其实这个配置文件可以直接复制 /etc/nginx/conf.d/default.conf 后做一下修改即可 配置文件内容如下: ~~~ # # server # server { listen 80; server_name www.test.com test.com; # 设置域名 index index.php index.html; #默认主页 root /var/www/html; # 站点目录 # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; #加载扩展配置 location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } ~~~ 重启 nginx ~~~ service nginx restart ~~~ 测试:访问:www.test.com ### 5. 使nginx支持PHP nginx安装后,默认是不能解析php文件的。需要在nginx的配置文件中增加php的支持配置项。 在这里咱们把php相关的配置做为nginx的扩展配置加入。 创建 /etc/nginx/default.d/php.conf ,在该文件中添加php的配置项: nginx关于php的配置咱们可以在nginx的默认配置中找到,直接复制过做一下修即可。 安装nginx后可以打开/etc/nginx/nginx.conf.default在这个文件中,可以找到以下配置内容: ![](https://box.kancloud.cn/886326c62d8df17c7771b98c9ee93534_956x535.png) > 把红线内的内容复制到php.conf中进行修即可 修改后的内容如下: ~~~ # nginx 支持 php location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } ~~~ > 在这个配置文件中,要注意的是 `fastcgi_param SCRIPT_FILENAME` `$document_root$fastcgi_script_name`;,为了增加通用性,咱们把这里的站点目录换成 `$document_root` 到这里重启 nginx ~~~ service nginx restart ~~~ 测试:访问:www.test.com ##到这里nginx就可以正常解析PHP了