GVKun编程网logo

thphp(tp5)项目网站从Apache换成nginx报500(apache网站转nginx)

28

对于thphp感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解tp5项目网站从Apache换成nginx报500,并且为您提供关于CentOS上如何把Web服务器从Apache换到Nginx

对于thphp感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解tp5项目网站从Apache换成nginx报500,并且为您提供关于CentOS上如何把Web服务器从Apache换到Nginx、Linux下,400-500并发,用Apache+PHP_MOD还是Nginx+PHP-fpm比较靠谱?、nginx 优化突破十万并发 nginx apache nginx php nginx rewrite、nginx 多个站点配置 nginx apache nginx php nginx rewrite的宝贵知识。

本文目录一览:

thphp(tp5)项目网站从Apache换成nginx报500(apache网站转nginx)

thphp(tp5)项目网站从Apache换成nginx报500(apache网站转nginx)

thPHP(tp5)项目网站从Apache换成Nginx报500

 

百度了一下,查看资料是Nginx配置fastcgi.conf的问题,打开文件编辑既可,如下图:

 

 

CentOS上如何把Web服务器从Apache换到Nginx

CentOS上如何把Web服务器从Apache换到Nginx

码农日记原创,转载请注明出处并给出原文链接!http://www.androiddev.net/webserver-apache-to-nginx/

我的网站在阿里云服务器上, 1G内存的配置,但用了一段时间,感觉Apache有些撑不出,想了想,还是换到目前最热门的Nginx吧。 这里把整个过程记录下来,与大家共享。

Nginx简介:

Nginx是一个高性能的HTTP服务器和反向代理服务器, 最大的优点是节省资源,适用于处理高并发的请求。

1. Nginx最初是按照反向代理设计的,和Apache不同,Nginx关心如何处理url,而不是文件!

2. Apache 是个基于进程处理的web服务器,如果同时有多个请求,必须要启动多个进程来处理。 这样在高负载的情况下,资源的消耗和响应的速度都会有很大的问题。 而Nginx是个基于事件(event)的异步处理模式, 下面是Nginx的一个简单的示意图,有一个Master进程,Maste进程负责系统配置,管理socket,以及管理一个或是多个Worker进程。 而Worker进程接收和处理来自用户(浏览器)的请求。一般来讲,一个worker进程可以同时处理上千个用户的连接请求。每个worker进程采用异步的,基于event的方式来处理用户的请求。对于HTML的静态页面,Nginx会自行来处理,但对于PHP,JSP,Python等动态页面,Nginx是通过FastCGI(或者SCGI,UWsgi)来把动态页面的请求交给相应的处理程序来处理。

安装Nginx

需要注意的是,在CentOS的YUM的基础的容器中,并没有Nginx和PHP-fpm的RPM包。这两个RMP包在epel的容器中, 虽然你可以从官网下载RPM包来安装,但我个人建议,如果你的CentOS/Redhat中没有加入YUM的epel容器,还是先把这个yum容器加上去比较好,以后可以省无数的折腾。epel具体的安装方法,我在Redhat/CentOS 软件安装之RPM和YUM这篇文章中有介绍。

yum的容器库中加入了epel容器后,在CentOS上安装Nginx就非常简单,运行下面的命令就可以了。

1 yum install Nginx

安装玩以后,会发现Nginx的配置文件放在 /etc/Nginx目录下, 一般在缺省的情况下,web的root目录会在/usr/share/ngxin/html中。

安装完Nginx以后,我们要测试一下是否安装成功了.

如果之前已经安装过Apache的话,先要把Apache的服务停掉。

/etc/init.d/httpd stop #停掉apache服务
2
3
chkconfig httpd off #开机重启后,apache服务不再启动

Linux下,400-500并发,用Apache+PHP_MOD还是Nginx+PHP-fpm比较靠谱?

Linux下,400-500并发,用Apache+PHP_MOD还是Nginx+PHP-fpm比较靠谱?

一直使用Ubuntu自带的LAMP做比较小的项目,最近遇到对并发要求比较高的,在考虑是否用Nginx+PHP-fpm,由于没有详细测试过,所以征求下过来人的意见。另外Nginx+PHP-fpm应该怎么设置性能方面的参数呢?

nginx 优化突破十万并发 nginx apache nginx php nginx rewrite

nginx 优化突破十万并发 nginx apache nginx php nginx rewrite

nginx 多个站点配置 nginx apache nginx php nginx rewrite

nginx 多个站点配置 nginx apache nginx php nginx rewrite

服务器地址:192.168.1.231

域名:test1.com 目录:/www/test1.com

域名:test2.com 目录:/www/test2.com

该配置思路

把2个站点 test1.com, test2.com 放到 nginx 可以访问的目录 /www/
给每个站点分别创建一个 nginx 配置文件 test1.com.conf,test2.com.conf, 并把配置文件放到 /etc/nginx/vhosts/
然后在 /etc/nginx.conf 里面加一句 include 把步骤2创建的配置文件全部包含进来(用 * 号)
重启 nginx

实际操作:

[root@localhost ~]# mkdir /www/test1.com
[root@localhost ~]# mkdir /www/test2.com
[root@localhost ~]# cd /etc/nginx/
[root@localhost nginx]# mkdir vhosts
[root@localhost nginx]# cd vhosts/
[root@localhost vhosts]# vi test1.com.conf 
#增加以下内容
server {
        listen  80;
        server_name  test1.com www.test1.com;
        access_log  /www/access_test1.log  main;
        location / {
            root   /www/test1.com;
            index  index.php index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ .php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.html;
            fastcgi_param  SCRIPT_FILENAME  /www/test1.com/$fastcgi_script_name;
            include        fastcgi_params;
        }
        location ~ /.ht {
            deny  all;
        }
}
[root@localhost vhosts]# vi test2.com.conf 
#增加以下内容
server {
        listen  80;
        server_name  test2.com www.test2.com;

        access_log  /www/access_test2.log  main;

        location / {
            root   /www/test2.com;
            index  index.php index.html index.htm;
        }

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

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

        location ~ /.ht {
            deny  all;
        }
}
登录后复制

修改nginx.conf

备份配置文件

立即学习“PHP免费学习笔记(深入)”;


[root@localhost ~]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf20160425
[root@localhost ~]# vi /etc/nginx/nginx.conf.
#修改成以下内容
user  nginx;
worker_processes  1;

# main server error log
error_log       /var/log/nginx/error.log ;
pid     /var/run/nginx.pid;
events {
        worker_connections  1024;
}
# main server config
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"'';
        sendfile        on;
        #tcp_nopush     on;
        #keepalive_timeout  0;
        keepalive_timeout  65;
        gzip  on;
        server {
                listen         80;
                server_name     _;
                access_log      /var/log/nginx/access.log main;
                server_name_in_redirect  off;
                location / {
                        root  /usr/share/nginx/html;
                        index index.html;
                }
        }
    # 这一行是加载上面的配置文件
    include /etc/nginx/vhosts/*;
}

重起nginx服务
[root@localhost ~]# service nginx restart
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
[root@localhost ~]# 
登录后复制

下面我们进行测试是否成功

将nginx默认页面/usr/html/index.html 分别拷备到/www/test1.com和/www/test2.com里面

然后将index.html里面的内容分别改成test1.com和test2.com

测试机为windowns

修改host文件

# localhost name resolution is handled within DNS itself.

#    127.0.0.1       localhost

#    ::1             localhost

192.168.1.231    www.test1.com

192.168.1.231    www.test2.com

在该服务器上分别打开www.test1.com

test1.com

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.

Commercial support is available at nginx.com.

Thank you for using nginx.

在该服务器上分别打开www.test2.com

test2.com

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.

Commercial support is available at nginx.com.

Thank you for using nginx.

测试成功!!!!!


以上就介绍了nginx 多个站点配置,包括了nginx方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

关于thphptp5项目网站从Apache换成nginx报500的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于CentOS上如何把Web服务器从Apache换到Nginx、Linux下,400-500并发,用Apache+PHP_MOD还是Nginx+PHP-fpm比较靠谱?、nginx 优化突破十万并发 nginx apache nginx php nginx rewrite、nginx 多个站点配置 nginx apache nginx php nginx rewrite的相关信息,请在本站寻找。

本文标签: