ubuntu16.04 nginx1.10.3 配置虛擬主機
阿新 • • 發佈:2019-01-25
1.首先開啟nginx.conf配置,看到nginx.conf檔案裡寫有引入sites-enabled目錄下的檔案件。開啟sites-enabled目錄下的default檔案,看到裡面都是配置server網點的。
我配置如下,我會在配置里加說明
server {
listen 80; //監聽80埠
server_name a.test.com;//配置域名,改域名和ubuntu下的hosts一樣配置。
root /var/www/html/shouqan;//在位址列上輸入域名,就會來到這個目錄
location / {
index index.html index.php; //來到上面的那個目錄,根據目錄下有是否有index.html,index.php才會顯示出來
}
location ~ \.php { //解釋php檔案的
include snippets/fastcgi-php.conf;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
2.ubuntu16.04下的hosts配置如下
[email protected] :/etc# cat hosts
127.0.0.1 localhost
127.0.1.1 lion-Aspire-E1-451G
127.0.0.1 a.test.com //對應nginx的server配置
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters