将Nachex替换为Laravel Web服务器

时间:2017-04-06 22:34:04

标签: php nginx laravel-5

我们目前使用apache作为Web服务器运行Laravel,并希望切换到Nginx。

我们有Nginx设置,但在尝试切换到Ngnix时遇到了权限问题。 ngnix都无法编写会话和缓存。

作为解决方法,我们试图将ngnix用户放在与apache相同的组中,然后将会话和缓存文件夹的写权限授予apache,但这并没有成功。

我们尝试过的另一个解决方案是使用apache用户/组运行ngnix,但我们也不是很幸运。

Nginx配置:

# user nginx;
user apache apache;
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;

    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;
        include /etc/nginx/default.d/*.conf;

    server {
        listen       <port> default_server;
        listen       [::]:<port> default_server;
        server_name  _;
        root         <server root>;


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

        location / {
        }

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

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }

}

其中一个虚拟主机(服务器块):

server {
    listen       <port>;
    root <virtual host folder>;
    index index.php index.html index.htm;
    server_name  <virtual host>;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    } 


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

挑战是让Nginx在会话上写作:

[2017-04-06 21:35:06] production.ERROR: exception 'ErrorException' with message 'file_put_contents(storage/framework/sessions/VkdMhjlYVEi3DvLyK7tQD2tjn8sFFzj2Y8X5erkW): failed to open stream: Permission denied' in vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:111

或缓存:

[2017-04-05 21:47:37] production.ERROR: exception 'ErrorException' with message 'file_put_contents(cache/7c/26/7c26fc7024a54df9633e679cfdf19309a84402c7): failed to open stream: Permission denied' in vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:111

是否可以将正在运行的Laravel安装从Apache无缝切换到Nginx?我们正在避免重新重新安装Laravel。

0 个答案:

没有答案