Nginx 配置 php-fpm

nginx 配置文件示例:

server {
    listen       80;
    server_name  www.test.com;
    set $root_path  '/usr/local/project/项目index目录';
    root $root_path;
    index index.php index.html index.htm;
    try_files $uri $uri/ @rewrite;
    location @rewrite {
        rewrite ^/(.*)$ /index.php?_url=/$1;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  /index.php;
        fastcgi_split_path_info    ^(.+\.php)(/.+)$;

        fastcgi_param PATH_INFO    $fastcgi_path_info;

        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

        include            fastcgi_params;

        client_max_body_size 30m;
    }

    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {

           root $root_path;

    }

    location ~ /\.ht {
        deny  all;
    }
}

本地DNS配置

# vim /etc/hosts
127.0.0.1  www.test.com   //添加这一句

//查看是否配置成功
# ping www.test.com
PING www.test.com (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.035 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.073 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.074 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.076 ms
64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.065 ms
64 bytes from localhost (127.0.0.1): icmp_seq=6 ttl=64 time=0.073 ms
64 bytes from localhost (127.0.0.1): icmp_seq=7 ttl=64 time=0.080 ms
64 bytes from localhost (127.0.0.1): icmp_seq=8 ttl=64 time=0.118 ms
64 bytes from localhost (127.0.0.1): icmp_seq=9 ttl=64 time=0.078 ms
64 bytes from localhost (127.0.0.1): icmp_seq=10 ttl=64 time=0.073 ms
...

ok!

你可能感兴趣的:(Nginx 配置 php-fpm)