nginx和php的配置

1、修改php-fpm.conf(/etc/php-fpm.conf)
如果有/etc/php-fpm.d/www.conf文件,就在该文件修改
可以输入下面命令查找:
find / -name php-fpm.conf
find / -name www.conf
2、在上述文件修改:
;listen = 127.0.0.1:9000//注释这个
listen = /dev/shm/php-cgi.sock//添加这个
user = nginx
group = nginx
3、修改nginx配置文件nginx.conf
find / -name nginx.conf//查找nginx.conf
修改完后重起:
service nginx restart
service php-fpm restart
配置文件如下:
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/
#修改权限为root
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  localhost;
        #修改root指向的路径(你的项目路径)
        #root         /usr/share/nginx/html;
        root         /var/web/learnlaravel5/public;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
            #laravel配置
            try_files $uri $uri/ /index.php?$query_string;
            index index.php index.html index.htm;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
        location ~ \.php$ {
            # 设置监听端口
            #fastcgi_pass   127.0.0.1:9000;
            fastcgi_pass unix:/dev/shm/php-cgi.sock;
            # 设置nginx的默认首页文件(上面已经设置过了,可以删除)
            fastcgi_index  index.php;
            # 设置脚本文件请求的路径
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            # 引入fastcgi的配置文件
            include   fastcgi_params;
        }
    }
}

猜你喜欢

转载自blog.csdn.net/zwhsoul/article/details/80272431