接上一篇文章centos7搭建lnmp (php7 + mysql5.7 +nginx1.8)
配置好了當然到配置虛擬主機域名了
- 首先先在 /etc/nginx (在安裝目錄中),新建一個vhosts目錄
mkdir vhosts
2. 在vhosts新建一個文件(名稱建議是你的域名.conf),並寫入
server {
listen 80;
server_name xxx.com; //這是網站域名
access_log /var/log/nginx/access_domain1.log main; //這是記錄的日誌,養成看日誌的習慣
root /www/php/blog; //這是網站根目錄
location / {
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php,phpinfo.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
接着在 /etc/nginx/nginx.conf 中的http節點中,建議是server節點前加入引用
最後運行
nginx -s reload
然後運行瀏覽器即可看到效果
建議:如果出錯了就找到你的日誌文件,查看錯誤原因,要養成查看錯誤日誌的習慣