启动nginx
1 | nginx |
什么都不返回,表示启动成功。
在浏览器打开你的服务器ip,显示如下类似界面。
nginx安装和启动都很正常。
现在要用nginx访问php文件。
1.把如下文件index.php放入nginx下面的html文件夹内,并删除index.html.
1 | cd /usr/share/nginx/html |
2.同时更改nginx.conf 配置文件为
此处只贴出server部分
1 | /etc/nginx/nginx .conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | server { listen 80; server_name 121.42.**.**; // 你自己的ip location / { root html; index index.php index.html index.htm; } error_page 500 502 503 504 /50x .html; location = /50x .html { root html; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi.conf; } } |
重启nignx nginx -s reload
再次访问服务器ip。
这个页面的意思是服务器不认识php文件,原因是我们的php还没有打开,
在linux中打开php需要php-fpm,我们要用yum安装php-fpm。
1 | yum install php70-php-fpm |
把php-fpm加入环境变量,运行php-fpm,无返回,证明启动成功,刷新页面。
到这个时候环境搭建成功。