nginx配置php的心得记录

文章讲述了如何配置Nginx以支持不同的用户,特别是针对PHP-FPM的配置,包括创建第二个PHP-FPM进程,更改监听端口和PID,以及设置不同用户的socket权限。用户可以通过这种方式实现多用户环境下的PHP服务隔离。
摘要由CSDN通过智能技术生成

nginx.conf可以配置 不同的用户

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #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   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

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


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

里面配置php的启动的走的sock

然后php的sock里面也可以配置不同用户

1、

创建第二个php-fpm进程所使用的主配置文件

复制主配置文件 cp /etc/php-fpm.conf /etc/php-fpm2.conf
2)复制子配置文件 cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www2.conf (注意子配置文件名会跟我这里有所不同注意www.conf是否存在,用存在的作为复制对象)

3)更改子配置文件 www2.conf的配置

listen = 127.0.0.1:9001 – 更改www2.conf 的监听端口

4)更改主配置文件php-fpm2.conf的配置

include=/etc/php-fpm.d/www2.conf – 将配置改成复制出来的www2.conf

pid = /run/php-fpm/php-fpm2.pid – 区分php-fpm2的pid 方便之后对该php-fpm进行关闭启动

5)启动php-fpm2.conf

linux命令:/usr/sbin/php-fpm -y /etc/php-fpm2.conf – 启动php-fpm:php-fpm启动脚本 -y php-fpm配置。对该命令不解的自行百度,php-fpm命令解析

6)检查是否成功启动php-fpm2

linux命令:ps aux | grep php-fpm

2、

like this /opt/php-5.6.3/etc/fpm.d/user1.conf

[user1]
listen.owner = user1
listen.group = user1
user = user1
group = user1
listen = /opt/php-5.6.3/sockets/user1.sock
listen.mode = 0666
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值