centos6 安装nginx最新稳定版

本文详细介绍了如何在CentOS系统中配置Nginx和PHP-FPM,包括设置Nginx仓库、编辑配置文件、启动服务等步骤,帮助读者实现网站的快速部署。

首先, 看这里: http://nginx.org/en/linux_packages.html#stable

 

 

第一步: 在/etc/yum.repos.d/下创建nginx.repo文件

第二步: 编辑nginx.repo文件, 内容如下: 

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

第三步: 安装nginx

yum install nginx

第四步: 编辑nginx.conf

vim /etc/nginx/nginx.conf
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.php 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   /usr/share/nginx/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;
        root           /usr/share/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        # fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME  $document_root$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;
    #}
}

第五步: 启动php-fpm(你可以将它理解为PHP的解释器)

service php-fpm start
[root@proxyin php-fpm.d]# ps -ef | grep php-fpm
root       9707      1  0 03:41 ?        00:00:00 php-fpm: master process (/etc/php-fpm.conf)
apache     9708   9707  0 03:41 ?        00:00:00 php-fpm: pool www            
apache     9709   9707  0 03:41 ?        00:00:00 php-fpm: pool www            
apache     9710   9707  0 03:41 ?        00:00:00 php-fpm: pool www            
apache     9711   9707  0 03:41 ?        00:00:00 php-fpm: pool www            
apache     9712   9707  0 03:41 ?        00:00:00 php-fpm: pool www            
root       9715   7933  0 03:41 pts/3    00:00:00 grep php-fpm

第六步: 浏览器输入ip地址进行访问

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值