【Nginx】Nginx虛擬vhost配置檔案

小亮520cl發表於2016-08-11
Nginx可以採用vhost虛擬配置檔案配置多個conf,多個域名多個配置檔案方便管理
主配置檔案

  1. [root@iZ251xiy3yfZ conf]# more nginx.conf

  2. #user nobody;
  3. worker_processes 1;

  4. #error_log logs/error.log;
  5. #error_log logs/error.log notice;
  6. #error_log logs/error.log info;

  7. #pid logs/nginx.pid;


  8. events {
  9.     worker_connections 1024;
  10. }


  11. http {
  12. server
  13. {
  14.     listen 80;
  15.     server_name _;
  16.     root /tmp/fuckyou;
  17.     location /phpfpm-status
  18.     {
  19.         fastcgi_pass 127.0.0.1:9000;
  20.         fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
  21.         allow 127.0.0.1;
  22.         deny all;
  23.     }


  24.     location /nginx_status
  25.     {
  26.         stub_status on;
  27.         access_log off;
  28.         allow 127.0.0.1;
  29.         deny all;
  30.     }
  31. }
  32. server
  33.    {
  34.      listen 8080;
  35.      server_name _;
  36.      return 403;
  37.    }

  38. include vhost/*.conf;
  39. }



  1. 某個域名配置檔案

  1. [root@iZ251xiy3yfZ conf]# more vhost/testapi.luobohr.com.conf
  2.     server {
  3.         listen 80;
  4.         server_name testapi.luobohr.com ;
  5.         root /home/wwwroot/api.luobohr.com;    ##域名與目錄

  6.         location / {
  7.                 index index.php index.html;
  8.                 if ( !-e $request_filename){
  9.                         rewrite ^/(.*)$ /index.php?s=$1 last;
  10.                         break;
  11.                 }
  12.         }


  13.         location ~ .*\.(php|php5)?$ {
  14.             root /home/wwwroot/api.luobohr.com;          目錄

  15.                 try_files $uri =404;
  16.                 fastcgi_pass 127.0.0.1:9000;               ----php-fpm埠
  17.                 fastcgi_index index.php;
  18.                         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  19.                 include fastcgi_params;
  20.         }
  21.         location ~ /.git
  22.         {
  23.             return 403;
  24.         }
  25.          location ~* ^/Admin{
  26.             return 403;
  27.         }

  28.          location ~* ^/bank{
  29.             return 403;
  30.         } 
  31.     }

與http的alias差不多的
  1. cat /etc/httpd/conf.d/zabbix.conf
  2. #
  3. # Zabbix monitoring system php web frontend
  4. #

  5. Alias /zabbix /usr/share/zabbix

  6. <Directory "/usr/share/zabbix">
  7.     Options FollowSymLinks
  8.     AllowOverride None
  9.     Require all granted

  10.     <IfModule mod_php5.c>
  11.         php_value max_execution_time 300
  12.         php_value memory_limit 128M
  13.         php_value post_max_size 16M
  14.         php_value upload_max_filesize 2M
  15.         php_value max_input_time 300
  16.         php_value always_populate_raw_post_data -1
  17.         # php_value date.timezone Europe/Riga
  18.     </IfModule>
  19. </Directory>

  20. <Directory "/usr/share/zabbix/conf">
  21.     Require all denied
  22. </Directory>

  23. <Directory "/usr/share/zabbix/app">
  24.     Require all denied
  25. </Directory>

  26. <Directory "/usr/share/zabbix/include">
  27.     Require all denied
  28. </Directory>

  29. <Directory "/usr/share/zabbix/local">
  30.     Require all denied
  31. </Directory>
訪問http://****/zabbix/   指向這個目錄


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2123306/,如需轉載,請註明出處,否則將追究法律責任。

相關文章