nginx.conf:

  1. user              nginx;
  2. worker_processes  1;
  3. error_log         /var/log/nginx/error.log;
  4. pid               /var/run/nginx.pid;
  5. events {
  6.     worker_connections  1024;
  7. }
  8. http {
  9.     include       /etc/nginx/mime.types;
  10.     default_type  application/octet-stream;
  11.  
  12.     log_format  main  '$remote_addr - $remote_user [$time_local] "$request "'
  13.                       '$status $body_bytes_sent "$http_referer" '
  14.                       '"$http_user_agent" "$http_x_forwarded_for"';
  15.     access_log  /var/log/nginx/access.log  main;
  16.  
  17.     sendfile        on;
  18.     autoindex off;
  19.     map $scheme $fastcgi_https { ## Detect when HTTPS is used
  20.         default off;
  21.         https on;
  22.     }
  23.  
  24.     keepalive_timeout  10;
  25.  
  26.     gzip  on;
  27.     gzip_comp_level 2;
  28.     gzip_proxied any;
  29.     gzip_types      text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  30.  
  31.     # Load config files from the /etc/nginx/conf.d directory
  32.     include /etc/nginx/conf.d/*.conf;
  33. }

虚拟主机:

  1. server {
  2.     listen 80;
  3.     server_name DOMAIN.com;
  4.     rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
  5. }
  6.  
  7. server {
  8.     listen 80 default;
  9. ## SSL directives might go here
  10.     server_name www.DOMAIN.com *.DOMAIN.com; ## Domain is here twice so server_name_in_redirect will favour the www
  11.     root /var/www/vhosts/DOMAIN.com;
  12.  
  13.     location / {
  14.         index index.html index.php; ## Allow a static html file to be shown first
  15.         try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
  16.         expires 30d; ## Assume all files are cachable
  17.     }
  18.  
  19.     ## These locations would be hidden by .htaccess normally
  20.     location ^~ /app/                { deny all; }
  21.     location ^~ /includes/           { deny all; }
  22.     location ^~ /lib/                { deny all; }
  23.     location ^~ /media/downloadable/ { deny all; }
  24.     location ^~ /pkginfo/            { deny all; }
  25.     location ^~ /report/config.xml   { deny all; }
  26.     location ^~ /var/                { deny all; }
  27.  
  28.     location /var/export/ { ## Allow admins only to view export folder
  29.         auth_basic           "Restricted"; ## Message shown in login window
  30.         auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
  31.         autoindex            on;
  32.     }
  33.  
  34.     location  /. { ## Disable .htaccess and other hidden files
  35.         return 404;
  36.     }
  37.  
  38.     location @handler { ## Magento uses a common front handler
  39.         rewrite / /index.php;
  40.     }
  41.  
  42.     location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
  43.         rewrite ^(.*.php)/ $1 last;
  44.     }
  45.  
  46.     location ~ .php$ { ## Execute PHP scripts
  47.         if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
  48.  
  49.         expires        off; ## Do not cache dynamic content
  50.         fastcgi_pass   127.0.0.1:9000;
  51.         fastcgi_param  HTTPS $fastcgi_https;
  52.         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  53.         fastcgi_param  MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
  54.         fastcgi_param  MAGE_RUN_TYPE store;
  55.         include        fastcgi_params; ## See /etc/nginx/fastcgi_params
  56.     }
  57. }

发表评论

电子邮件地址不会被公开。 必填项已用*标注