nginx开发环境配置步骤:
1. 查看nginx配置文件位置:ps -ef |grep nginx
-c 是指用的 /etc/nginx/nginx.conf 这个的配置文件。
2. 查看配置文件: cat /etc/nginx/nginx.conf,最后几行中
nginx的虚拟域名配置都放这个里面了。 加载是以.conf 结尾的,在include conf.d/*.conf 下添加一条你自己的开发配置地址。如:include test/*.conf
3. 创建自己的目录:cd /etc/nginx 进入到这个目录后,mkdir yourlist创建自己的开发配置目录(yourlist即conf.d)
vim www.mysite.com.conf,编辑配置文件
server { #监听端口 listen 80; server_name www.mysite.com; #默认首页 index index.html index.php; #项目入口目录 root /home/workspace/www; #访问日志 main 是nginx.conf 定义好的日志格式,可以不加这个main access_log /var/log/nginx/www.mysite.com.access.log main; #错误日志 error_log /var/log/nginx/www.mysite.com.err.log error; #如果是404的错误跳转到设置的这个404.html error_page 404 /404.html; #php文件访问处理 location ~ [^/]\.php(/|$) { try_files $uri =404; fastcgi_pass unix:/var/run/php-cgi.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
4. 创建开发目录:
mkdir workplace 创建开发目录
cd workplace 进入到目录中
mkdir -p www 创建多个目录
cd www
vim index.php
<?php phpinfo(); ?>
给文件夹增加可执行权限:
chmod +x /home
chmod +x /home/workplace
chmod +x /home/www
5. 监测 nginx的配置文件是否有异常: /usr/sbin/nginx -t
如图所示就ok说明没问题;
6. /usr/sbin/nginx -s reload 加载你最新的配置
7. 绑定host域名
然后在浏览器上访问就好了。出来phpinfo()的内容了。