开发者社区> 问答> 正文

LNMPA,单独配置的问题 :报错

这LNMPA环境搭建,大家有人配过没?

我先说下我的想法:

nginx在前端做负载均衡并处理一些静态文件,比如js,css等.将动态文件丢给后端的apache

数据库这边的就先不说了,因为公司要用的postgresql,在另外的FWQ上安装的。

然后PHP用的是5.3.10,要安装php-fpm

apache2.2在后端处理nginx丢过来的PHP动态文件.

另外,PHP还要安装eaccelerator来加速。

现在问题是我已经配置好了php5.3.10+php-fpm+apache+fastcgi了,但好像apache2.4一直不成功,不知道为什么,现在连eaccelerator也装不上去。nginx这边配置文件怎么做?它貌似不需要运行PHP,也就不管它用什么方式来跑了吧?

展开
收起
kun坤 2020-06-20 13:47:32 42719 0
3 条回答
写回答
取消 提交回答
  • 2020-12-11 14:10:18
    赞同 展开评论 打赏
  • .php 做 提交到apache
    ######

    引用来自“滔哥”的答案

    .php 做 提交到apache
    不需要在nginx里面做配置嘛?
    ######中间层apache直接可以省略,直接nginx既做balance,也可以server######

    引用来自“Meso”的答案

    中间层apache直接可以省略,直接nginx既做balance,也可以server
    哎呀。这不是你说省略就省略的呀。需求要这么搞,就得这么搞呀。。。
    ######需要 怎么配置还得需要具体需求来看了。
    1:php和静态文件分别在两个不同的域,这是最好配置的了。
    2:如果都在一个域,但是静态文件又都在一个目录下,那就把这一个目录交给nginx处理,其它的交给apache处理
    3:这种是最麻烦的,到时都可能存在静态文件和php,那么把.js、.css、.flv、.swf、.gif、.png、.txt、.jpg、.jpeg,其它的都交给apache处理,如果有urlrewrite,但是后缀不带有html、htm等,那么htm、html也交给nginx处理,如果带有,那么只好都交给apache处理了
    ######nginx.conf
    user  www www;
    
    worker_processes 1;
    
    error_log  /home/wwwlogs/nginx_error.log  crit;
    
    pid        /usr/local/nginx/logs/nginx.pid;
    
    #Specifies the value for maximum file descriptors that can be opened by this process.
    worker_rlimit_nofile 51200;
    
    events
    	{
    		use epoll;
    		worker_connections 51200;
    	}
    
    http
    	{
    		include       mime.types;
    		default_type  application/octet-stream;
    
    		server_names_hash_bucket_size 128;
    		client_header_buffer_size 32k;
    		large_client_header_buffers 4 32k;
    		client_max_body_size 50m;
    
    		sendfile on;
    		tcp_nopush     on;
    
    		keepalive_timeout 60;
    
    		tcp_nodelay on;
    
    		fastcgi_connect_timeout 300;
    		fastcgi_send_timeout 300;
    		fastcgi_read_timeout 300;
    		fastcgi_buffer_size 64k;
    		fastcgi_buffers 4 64k;
    		fastcgi_busy_buffers_size 128k;
    		fastcgi_temp_file_write_size 256k;
    
    		gzip on;
    		gzip_min_length  1k;
    		gzip_buffers     4 16k;
    		gzip_http_version 1.0;
    		gzip_comp_level 2;
    		gzip_types       text/plain application/x-javascript text/css application/xml;
    		gzip_vary on;
    
    		#limit_zone  crawler  $binary_remote_addr  10m;
    
    server
    	{
    		listen       80;
    		server_name www.lnmp.org;
    		index index.html index.htm index.php;
    		root  /home/wwwroot;
    
    		location / {
    			try_files $uri @apache;
    			}
    
    		location @apache {
    			internal;
    			proxy_pass http://127.0.0.1:88;
    			include proxy.conf;
    			}
    
    		location ~ .*\.(php|php5)?$
    			{
    				proxy_pass http://127.0.0.1:88;
    				include proxy.conf;
    			}
    
    		location /status {
    			stub_status on;
    			access_log   off;
    		}
    
    		location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    			{
    				expires      30d;
    			}
    
    		location ~ .*\.(js|css)?$
    			{
    				expires      12h;
    			}
    
    		log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
                 '$status $body_bytes_sent "$http_referer" '
                 '"$http_user_agent" $http_x_forwarded_for';
    		access_log  /home/wwwlogs/access.log  access;
    	}
    include vhost/*.conf;
    }

    proxy.conf

    proxy_connect_timeout 30s;
    proxy_send_timeout   90;
    proxy_read_timeout   90;
    proxy_buffer_size    32k;
    proxy_buffers     4 32k;
    proxy_busy_buffers_size 64k;
    proxy_redirect     off;
    proxy_hide_header  Vary;
    proxy_set_header   Accept-Encoding '';
    proxy_set_header   Host   $host;
    proxy_set_header   Referer $http_referer;
    proxy_set_header   Cookie $http_cookie;
    proxy_set_header   X-Real-IP  $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;

    httpd.conf

    就不贴了 ,默认就行 ,伪静态 可以直接在 nginx .conf 里添加 ,也可以直接添加进httpd.conf

    仔细研究揣摩以上 代码

    ######

    好复杂,我一直都是nginx,php-fpm,mysql,这样的结构很好,不知道为什么要加一个apache,就算要平均负载,直接让dns,平均解析到不同的nginx上面,例如192.168.1.1,192.168.1.2,192.168.1.3.

    然后碰到.php就丢给内网的php-fpm,几台机子rsync一下,把php代码一致,每台台子开个600进程.集群memcache,主从mysql,就这架构,我想百万级是一点问题没有阿.

    ######

    引用来自“红星”的答案

    nginx.conf
    user  www www;
    
    worker_processes 1;
    
    error_log  /home/wwwlogs/nginx_error.log  crit;
    
    pid        /usr/local/nginx/logs/nginx.pid;
    
    #Specifies the value for maximum file descriptors that can be opened by this process.
    worker_rlimit_nofile 51200;
    
    events
    	{
    		use epoll;
    		worker_connections 51200;
    	}
    
    http
    	{
    		include       mime.types;
    		default_type  application/octet-stream;
    
    		server_names_hash_bucket_size 128;
    		client_header_buffer_size 32k;
    		large_client_header_buffers 4 32k;
    		client_max_body_size 50m;
    
    		sendfile on;
    		tcp_nopush     on;
    
    		keepalive_timeout 60;
    
    		tcp_nodelay on;
    
    		fastcgi_connect_timeout 300;
    		fastcgi_send_timeout 300;
    		fastcgi_read_timeout 300;
    		fastcgi_buffer_size 64k;
    		fastcgi_buffers 4 64k;
    		fastcgi_busy_buffers_size 128k;
    		fastcgi_temp_file_write_size 256k;
    
    		gzip on;
    		gzip_min_length  1k;
    		gzip_buffers     4 16k;
    		gzip_http_version 1.0;
    		gzip_comp_level 2;
    		gzip_types       text/plain application/x-javascript text/css application/xml;
    		gzip_vary on;
    
    		#limit_zone  crawler  $binary_remote_addr  10m;
    
    server
    	{
    		listen       80;
    		server_name www.lnmp.org;
    		index index.html index.htm index.php;
    		root  /home/wwwroot;
    
    		location / {
    			try_files $uri @apache;
    			}
    
    		location @apache {
    			internal;
    			proxy_pass http://127.0.0.1:88;
    			include proxy.conf;
    			}
    
    		location ~ .*\.(php|php5)?$
    			{
    				proxy_pass http://127.0.0.1:88;
    				include proxy.conf;
    			}
    
    		location /status {
    			stub_status on;
    			access_log   off;
    		}
    
    		location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    			{
    				expires      30d;
    			}
    
    		location ~ .*\.(js|css)?$
    			{
    				expires      12h;
    			}
    
    		log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
                 '$status $body_bytes_sent "$http_referer" '
                 '"$http_user_agent" $http_x_forwarded_for';
    		access_log  /home/wwwlogs/access.log  access;
    	}
    include vhost/*.conf;
    }

    proxy.conf

    proxy_connect_timeout 30s;
    proxy_send_timeout   90;
    proxy_read_timeout   90;
    proxy_buffer_size    32k;
    proxy_buffers     4 32k;
    proxy_busy_buffers_size 64k;
    proxy_redirect     off;
    proxy_hide_header  Vary;
    proxy_set_header   Accept-Encoding '';
    proxy_set_header   Host   $host;
    proxy_set_header   Referer $http_referer;
    proxy_set_header   Cookie $http_cookie;
    proxy_set_header   X-Real-IP  $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;

    httpd.conf

    就不贴了 ,默认就行 ,伪静态 可以直接在 nginx .conf 里添加 ,也可以直接添加进httpd.conf

    仔细研究揣摩以上 代码

    你这nginx里面的配置,是不是有用到fastcgi啊?这个东西放到nginx里面来干嘛?

    据我所了解的,apache是以fastcgi来跑PHP的,而PHP是用php-fpm来管理fastcgi的,对吧?

     

    ######你都 php-fpm了,还要apache干嘛######

    引用来自“xiaojia2008”的答案

    你都 php-fpm了,还要apache干嘛
    。。。。汗。。php-fpm是用来管理fastcgi的吧?要apache是要它以fastcgi方式来运行PHP呀。。。
    2020-06-20 13:48:00
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Patroni使用维护手册 立即下载
Data as a Service - 数据即服务 -- MongoDB⾼级应⽤模式 立即下载
《Nginx 代理系统常用手册》 立即下载