Ngnix 安装及配置

来源:互联网 发布:淘宝店铺口令怎么生成 编辑:程序博客网 时间:2024/05/17 22:06

安装Nginx

sudo apt-get install nginx

安装php及php常用插件
sudo apt-get install php5-cgi php-apc php5-curl php5-gd php5-mysql php5-mcrypt php5-memcache php5-memcached

安装Php-fpm

sudo apt-get install php5-fpm



配置

# You may add here your
# server {
#   ...
# }
# statements for each of your virtual hosts to this file
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

server {
    listen   8080; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default ipv6only=on; ## listen for ipv6
    root /var/nginx;
    index index.php index.html index.htm;
    # Make site accessible from http://localhost/
    server_name localhost;


    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to index.html
        index index.php
        try_files $uri $uri/ /index.html;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }


    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        deny all;
    }

    # Only for nginx-naxsi : process denied requests
    #location /RequestDenied {
        # For example, return an error code
        #return 418;
    #}

    #error_page 404 /404.html;
    # redirect server error pages to the static page /50x.html
    #
    #error_page 500 502 503 504 /50x.html;
    #location = /50x.html {
    #   root /usr/share/nginx/www;
    #}
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        # With php5-cgi alone:
        #fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
        fastcgi_intercept_errors on;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #location ~ /\.ht {
    #   deny all;
    #}
}


server {
    listen 8080;
    root /var/nginx/ecweb/src/www;
    index index.php index.html index.htm;
    server_name ya.com; #must oonfig to hosts file example: 127.0.0.1 ya.com

    set $application_env "development";

    location / {
      index  index.php index.html index.htm;
      if (-f $request_filename) {
        break;

      }

 if (-d $request_filename) {
         break;
      }
      rewrite ^(.+)$ /index.php last;
    }

    location ~ \.php$ {
       try_files $uri =404;
       fastcgi_index index.php;
       #fastcgi_pass 127.0.0.1:9000;
       fastcgi_pass unix:/var/run/php5-fpm.sock;
       include fastcgi_params;
       fastcgi_param SLIM_ENV_MODE $application_env;
    }
}

server {
     listen   8080;
     root /var/nginx/mm/src/www-admin;
     index index.php index.html;
     server_name admin.usercenter.mm.cn;
     location / {
         if (!-f $request_filename) {
             rewrite ^/(.+)$ /index.php?$1&;
         }
     }
     location ~ \.php$ {
         try_files $uri =404;
         fastcgi_index index.php;
         # fastcgi_pass 127.0.0.1:9000;
         fastcgi_pass unix:/var/run/php5-fpm.sock;
         #fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
         include fastcgi_params;
         fastcgi_param APPLICATION_ENV  $application_env;
     }
}


server {
     listen   8080;
     root /var/nginx/mm/src/www-overseas;
     index index.php index.html;
     server_name oe.mm.cn;
     location / {
          if (!-f $request_filename) {
              rewrite ^/(.+)$ /index.php?$1&;
          }
     }

     location ~ \.php$ {
          try_files $uri =404;
          fastcgi_index index.php;
          # fastcgi_pass 127.0.0.1:9000;
          fastcgi_pass unix:/var/run/php5-fpm.sock;
          #fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
          include fastcgi_params;
          fastcgi_param APPLICATION_ENV  $application_env;
     }
}

0 0
原创粉丝点击