只用改一個(gè)地方,在http模塊里面加入你要引用的html' target='_blank'>虛擬主機(jī)配置文件目錄即可:
例如:include /usr/local/nginx/default.d/*.conf;
http { log_format main $remote_addr - $remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; include /usr/local/nginx/default.d/*.conf; //就這里加一行就可以了}
2、建立虛擬主機(jī)配置目錄:
在/usr/local/nginx/下面建立default.d文件夾,專門放置網(wǎng)站的配置文件。
貼一個(gè)我的配置上來:
/usr/local/nginx/default.d/mytest.conf
server { listen 80 ; //注意這里,要把默認(rèn)的那個(gè)default_server去掉,因?yàn)槲覀冊谙旅嬉獑为?dú)配置域名訪問,所以這里不要留default_server,不然會(huì)報(bào)錯(cuò)。 server_name mytest.com; //這里寫你想設(shè)置的域名,可以寫多個(gè),與名之間用空格隔開 root /mnt/share/mytest.com; //這里是你虛擬機(jī)的根目錄,寫絕對路徑 # Load configuration files for the default server block. location / { index index.php index.html index.htm; //這里配置默認(rèn)訪問的頁面 location ~* /.php$ { //這里配置php解析.php文件 fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; error_page 404 /404.html; //默認(rèn)的錯(cuò)誤頁面 location = /40x.html { error_page 500 502 503 504 /50x.html; location = /50x.html {}
再來一個(gè):
server { listen 80; server_name www.mytest1.com; root /var/www/html; index index.html index.htm index.php; location / { try_files $uri $uri/ /index.php?$query_string; location = /favicon.ico { log_not_found off; location ~ /.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params;}
3、還想再建其他虛擬機(jī),一樣的,復(fù)制上面那個(gè)文件,修改我標(biāo)注的的那幾個(gè)地方即可!
4、虛擬機(jī)配置文件配置好了之后,還需要在linux下面的hosts文件下面加上以上域名,不然還是會(huì)訪問外網(wǎng)的哦。
vim /etc/hosts127.0.0.1 mytest1.com127.0.0.1 mytest.com
5、如果我們是要在windows下面訪問虛擬機(jī)里面的linux下面的網(wǎng)站,那么還要在windows下面配置hosts文件,所有的域名都指向linux服務(wù)器,例如:
192.168.0.27 mytest1.com192.168.0.27 mytest.com
6、遇到的問題:
nginx: [emerg] a duplicate default server for 0.0.0.0:80 in /etc/nginx/vhosts/
遇到這個(gè)問題,肯定是:
server { listen 80
這個(gè)地方80后面的東西都去掉,只留下端口號(hào)80,去掉就可以解決這個(gè)問題了。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,更多相關(guān)內(nèi)容請關(guān)注PHP !
相關(guān)推薦:
Nginx配置PATHINFO隱藏thinkphp index.php
以上就是如何解決nginx配置多個(gè)站點(diǎn)的共用80端口的問題的詳細(xì)內(nèi)容,PHP教程
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。
新聞熱點(diǎn)
疑難解答
圖片精選