nginx的配置

技術小胖子發表於2017-11-09

lnmpa的環境。

[root@abc conf]# vi /usr/local/nginx/nginx.conf

  gzip_vary on;
  gzip_types
    text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
    text/javascript application/javascript application/x-javascript
    text/x-json application/json application/x-web-app-manifest+json
    text/css text/plain text/x-component
    font/opentype application/x-font-ttf application/vnd.ms-fontobject
    image/x-icon;
  gzip_disable "MSIE [1-6].(?!.*SV1)";

  #If you have a lot of static files to serve through Nginx then caching of the files` metadata (not the actual files` contents) can save some latency.
  open_file_cache max=1000 inactive=20s;
  open_file_cache_valid 30s;
  open_file_cache_min_uses 2;
  open_file_cache_errors on;

######################## default ############################
  server {
    listen 80;
    server_name _;
    access_log /data/wwwlogs/access_nginx.log combined;
    root /data/wwwroot/www.***.com/public;
    index index.html index.htm index.php;
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    location /nginx_status {

      stub_status on;
      access_log off;
      allow 127.0.0.1;
      deny all;
    }
    location / {
      try_files $uri @apache;
    }
    location @apache {
      proxy_pass http://127.0.0.1:88;
      include proxy.conf;
    }
    location ~ [^/].php(/|$) {
      proxy_pass http://127.0.0.1:88;
      include proxy.conf;
    }
    location ~ .*.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
      expires 30d;
      access_log off;
    }
    location ~ .*.(js|css)?$ {
      expires 7d;
      access_log off;
    }
    location ~ /.ht {
      deny all;
    }
  }
########################## vhost #############################
  include vhost/*.conf;
}

[root@abc vhost]# vi /usr/local/nginx/conf/vhost/www.***.com.conf

server {
  listen 443;
  #listen 80;
  ssl on;
  server_name www.***.com;

  ssl_certificate   ../cert/21234224312342.pem;
  ssl_certificate_key  ../cert/21234224312342.key;
  ssl_session_timeout 5m;
  ssl_ciphers ABCDE-ABC-AES128-ABC-SHA256:ABCDE:ABCD:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_prefer_server_ciphers on;

  access_log off;
  index index.html index.htm index.php;
  root /data/wwwroot/www.***.com/public;

  location / {
    try_files $uri @apache;
  }
  location @apache {
    proxy_pass http://127.0.0.1:88;
    include proxy.conf;
  }
  location ~ .*.(php|php5|cgi|pl)?$ {
    proxy_pass http://127.0.0.1:88;
    include proxy.conf;
  }
  location ~ .*.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
    expires 30d;
    access_log off;
  }
  location ~ .*.(js|css)?$ {
    expires 7d;
    access_log off;
  }
  location ~ /.ht {
    deny all;
  }
}

[root@abc vhost]# vi /usr/local/apache/conf/vhost/www.***.com.conf

<VirtualHost *:88>
  ServerAdmin admin@example.com
  DocumentRoot "/data/wwwroot/www.***.com/public"
  ServerName www.***.com

  ErrorLog "/data/wwwlogs/www.***.com_error_apache.log"
  CustomLog "/dev/null" common
<Directory "/data/wwwroot/www.***.com/public">
  SetOutputFilter DEFLATE
  Options FollowSymLinks ExecCGI
  Require all granted
  AllowOverride All
  Order allow,deny
  Allow from all
  DirectoryIndex index.html index.php
</Directory>

</VirtualHost>



本文轉自phpervip 51CTO部落格,原文連結:http://blog.51cto.com/phpervip/2051206,如需轉載請自行聯絡原作者