只用改一個地方,在http模塊里面加入你要引用的html' target='_blank'>虛擬主機配置文件目錄即可:
例如: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、建立虛擬主機配置目錄:
在/usr/local/nginx/下面建立default.d文件夾,專門放置網站的配置文件。
貼一個我的配置上來:
/usr/local/nginx/default.d/mytest.conf
server { listen 80 ; //注意這里,要把默認的那個default_server去掉,因為我們在下面要單獨配置域名訪問,所以這里不要留default_server,不然會報錯。 server_name mytest.com; //這里寫你想設置的域名,可以寫多個,與名之間用空格隔開 root /mnt/share/mytest.com; //這里是你虛擬機的根目錄,寫絕對路徑 # Load configuration files for the default server block. location / { index index.php index.html index.htm; //這里配置默認訪問的頁面 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; //默認的錯誤頁面 location = /40x.html { error_page 500 502 503 504 /50x.html; location = /50x.html {}
再來一個:
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、還想再建其他虛擬機,一樣的,復制上面那個文件,修改我標注的的那幾個地方即可!
4、虛擬機配置文件配置好了之后,還需要在linux下面的hosts文件下面加上以上域名,不然還是會訪問外網的哦。
vim /etc/hosts127.0.0.1 mytest1.com127.0.0.1 mytest.com
5、如果我們是要在windows下面訪問虛擬機里面的linux下面的網站,那么還要在windows下面配置hosts文件,所有的域名都指向linux服務器,例如:
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/
遇到這個問題,肯定是:
server { listen 80
這個地方80后面的東西都去掉,只留下端口號80,去掉就可以解決這個問題了。
以上就是本文的全部內容,希望對大家的學習有所幫助,更多相關內容請關注PHP !
相關推薦:
Nginx配置PATHINFO隱藏thinkphp index.php
以上就是如何解決nginx配置多個站點的共用80端口的問題的詳細內容,PHP教程
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答
圖片精選