国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

lnmp環境nginx 配置多虛擬主機例子

2024-08-27 23:59:46
字體:
來源:轉載
供稿:網友

配置多虛擬主機是每一臺WEB服務器幾乎會做的一個動作了,特別是我們這種小站長了,下文小編來為各位介紹lnmp環境nginx 配置多虛擬主機例子,希望例子可以幫助到大家.

1、首先進入 /usr/local/nginx/conf/ 目錄(自己nginx安裝的路徑),剛編譯好的nginx 在這個目錄下是木有 vhost 目錄的,創建好這個目錄后,打開nginx.conf 文件,在 http 范圍內添加 include vhost/*.conf,包含創建的虛擬主機配置文件,然后保存,創建虛擬目錄共用的server文件,就是每個conf都會使用到的配置項,我們把他獨立成一個模塊供大家使用.

server.conf文件:

  1. location ~ .*/.(php|php5)?$ 
  2.     { 
  3.       #fastcgi_pass unix:/tmp/php-cgi.sock; 
  4.      fastcgi_pass 127.0.0.1:9000; 
  5.       fastcgi_index index.php; 
  6.       include fastcgi.conf; 
  7.     } 
  8.     location ~ .*/.(gif|jpg|jpeg|png|bmp|swf|ico)$ 
  9.     { 
  10.       expires 30d; 
  11.   # access_log off; 
  12.    } 
  13.     location ~ .*/.(js|css)?$ 
  14.     { 
  15.       expires 15d; 
  16.    # access_log off; 
  17.    } 
  18. fastcgi_index: (nginx的默認首頁文件) 

如果URI以斜線結尾,文件名將追加到URI后面,這個值將存儲在變量$fastcgi_script_name中.

例如:

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;

fastcgi_pass:指定FastCGI服務器監聽端口與地址,可以是本機或者其它.

用netstat -tln 查看端口使用情況:

tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN

可以看到9000端口處于監聽狀態:另外的其他fastcgi配置,放入fastcgi.conf公用配置文件中,server.conf 來包含他.

fastcgi.conf文件相關配置項:

  1. ?fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;#腳本文件請求的路徑   
  2.  
  3. fastcgi_param  QUERY_STRING       $query_string; #請求的參數;如?app=123   
  4. fastcgi_param  REQUEST_METHOD     $request_method; #請求的動作(GET,POST)   
  5. fastcgi_param  CONTENT_TYPE       $content_type; #請求頭中的Content-Type字段   
  6. fastcgi_param  CONTENT_LENGTH     $content_length; #請求頭中的Content-length字段。     
  7. fastcgi_param  SCRIPT_NAME        $fastcgi_script_name; #腳本名稱    
  8. fastcgi_param  REQUEST_URI        $request_uri; #請求的地址不帶參數   
  9. fastcgi_param  DOCUMENT_URI       $document_uri; #與$uri相同。    
  10. fastcgi_param  DOCUMENT_ROOT      $document_root; #網站的根目錄。在server配置中root指令中指定的值    
  11. fastcgi_param  SERVER_PROTOCOL    $server_protocol; #請求使用的協議,通常是HTTP/1.0或HTTP/1.1。     
  12. fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;#cgi 版本   
  13. fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;#nginx 版本號,可修改、隱藏   
  14. fastcgi_param  REMOTE_ADDR        $remote_addr; #客戶端IP   
  15. fastcgi_param  REMOTE_PORT        $remote_port; #客戶端端口   
  16. fastcgi_param  SERVER_ADDR        $server_addr; #服務器IP地址   
  17. fastcgi_param  SERVER_PORT        $server_port; #服務器端口   
  18. fastcgi_param  SERVER_NAME        $server_name; #服務器名,域名在server配置中指定的server_name 
  19. #fastcgi_param  PATH_INFO           $path_info;#可自定義變量   
  20. # PHP only, required if PHP was built with --enable-force-cgi-redirect   
  21. #fastcgi_param  REDIRECT_STATUS    200; 

2、準備好了公用文件server.conf 和 fastcgi.conf 后,進入vhost目錄,之前手動創建的,創建虛擬主機.

  1. vim test.conf; 
  2. server 
  3.         listen 80; 
  4.         server_name test.cn; 
  5.         index index.html index.htm index.php; 
  6.         root /var/www/test; 
  7.         access_log /var/www/logs/test.log; 
  8.         error_log off; 
  9.         location / { 
  10.                 try_files $uri $uri/ /index.php$uri?$args; 
  11.         } 
  12.         if (!-e $request_filename) { 
  13.                 rewrite ^(.*)$ /index.php?s=$1 last; 
  14.                 break; 
  15.         } 
  16.         include server.conf; 

test.conf 虛擬主機文件配置完成

重啟nginx:

記得先驗證測試后再重啟,否則會出現nginx 重啟不來.

測試:/usr/local/nginx/sbin/nginx -t

沒問題后進行重啟:

重啟:/usr/local/nginx/sbin/nginx -s reload

如果沒有域名來解析指定到自己的主機ip,可以直接把自己的主機ip 指到本地,編輯C:/Windows/System32/drivers/etc/hosts 文件就可,加入:

  1. <二、我的實例> 
  2. --------- vhosts/led.conf 
  3.   server { 
  4.         listen       80; 
  5.         server_name   www.led.com 
  6.         index index.html index.htm index.php; 
  7.         root /usr/local/vhost/led; 
  8.         #charset koi8-r; 
  9.         #access_log  logs/host.access.log  main; 
  10.         location / { 
  11.             root  /usr/local/vhost/led; 
  12.             index  index.html index.htm index.php; 
  13.         } 
  14.         #error_page  404              /404.html; 
  15.         # redirect server error pages to the static page /50x.html 
  16.         # 
  17.         error_page   500 502 503 504  /50x.html; 
  18.         location = /50x.html { 
  19.             root   html; 
  20.         } 
  21.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80 
  22.         # 
  23.         #location ~ /.php$ { 
  24.         #    proxy_pass   http://127.0.0.1; 
  25.         #} 
  26.  
  27.     location ~ .*/.(php|php5)?$ 
  28.        { 
  29.         #fastcgi_pass unix:/tmp/php-cgi.sock; 
  30.          fastcgi_pass  127.0.0.1:9000; 
  31.          fastcgi_index index.php; 
  32.          fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name
  33.         include fastcgi_params; 
  34.        }      
  35.     location ~ .*/.(gif|jpg|jpeg|png|bmp|swf)$ 
  36.        { 
  37.         expires 30d; 
  38.        } 
  39.        location ~ .*/.(js|css)?$ 
  40.       { 
  41.        expires 1h; 
  42.        } 
  43.     log_format access '$remote_addr - $remote_user [$time_local] "$request" ' 
  44.                       '$status $body_bytes_sent "$http_referer" ' 
  45.                          '"$http_user_agent" $http_x_forwarded_for'
  46.         
  47.     } 
  48. ---------------- nginx.conf 
  49. user  nginx nginx; 
  50. worker_processes  8; 
  51. error_log  logs/error.log; 
  52. #error_log  logs/error.log  notice; 
  53. #error_log  logs/error.log  info; 
  54. pid        /usr/local/nginx/nginx.pid; 
  55. worker_rlimit_nofile 65535; 
  56. events { 
  57.     use epoll; 
  58.     worker_connections  65535; 
  59.  
  60. http { 
  61.     include       mime.types; 
  62.     default_type  application/octet-stream; 
  63.     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ' 
  64.     #                  '$status $body_bytes_sent "$http_referer" ' 
  65.     #                  '"$http_user_agent" "$http_x_forwarded_for"'
  66.     #access_log  logs/access.log  main; 
  67.     server_names_hash_bucket_size 128; 
  68.     client_header_buffer_size 32k; 
  69.     large_client_header_buffers 4 32k; 
  70.     client_max_body_size 8m; 
  71.     sendfile        on; 
  72.     tcp_nopush     on; 
  73.     #keepalive_timeout  0; 
  74.     keepalive_timeout  65; 
  75.     tcp_nodelay on; 
  76.     fastcgi_connect_timeout 300; 
  77.     fastcgi_send_timeout 300; 
  78.     fastcgi_read_timeout 300; 
  79.     fastcgi_buffer_size 64k; 
  80.     fastcgi_buffers 4 64k; 
  81.     fastcgi_busy_buffers_size 128k; 
  82.     fastcgi_temp_file_write_size 128k;   
  83.     gzip  on;  //Vevb.com 
  84.     gzip_min_length 1k; 
  85.     gzip_buffers   4 16k; 
  86.     gzip_http_version 1.0; 
  87.     gzip_comp_level 2; 
  88.     gzip_types   text/plain application/x-javascript text/css application/xml; 
  89.     gzip_vary on; 
  90.     server { 
  91.         listen 80; 
  92.         server_name _; 
  93.         server_name_in_redirect off; 
  94.         location / { 
  95.         root /usr/share/nginx/html; 
  96.         index index.html; 
  97.         } 
  98.         } 
  99.         # 包含所有的虛擬主機的配置文件 
  100.         include /usr/local/nginx/conf/vhosts/*; 
  101.        
  102. }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 德惠市| 惠州市| 长顺县| 汾阳市| 镶黄旗| 平遥县| 龙里县| 茂名市| 西盟| 绥滨县| 登封市| 丹凤县| 南溪县| 雷波县| 容城县| 论坛| 河曲县| 绥德县| 五指山市| 德令哈市| 苏州市| 阳城县| 正阳县| 大安市| 阳朔县| 五台县| 罗田县| 邛崃市| 额敏县| 福清市| 莎车县| 都江堰市| 两当县| 山东省| 汉寿县| 叙永县| 乐都县| 肥西县| 泸溪县| 法库县| 四平市|