centos6搭建智能Nginx服务器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos6搭建智能Nginx服务器相关的知识,希望对你有一定的参考价值。

下载nginx

下载地址:http://nginx.org/download/
  • 下载后解压nginx到/usr/local/后,执行编译,编译时需要预先加模块;

通过Nginx支持php编程

本人通过yum源安装php-fpm

配置Nginx.conf文件

worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 10080;
server_name ly2016.club www.ly2016.club;
root /liuhome/nginx/html;
index index.html index.htm index.php;
location / {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ .php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:19001;
}
include /usr/local/nginx/conf.d/*.conf;
server {
listen 10080 default_server;
servername ;
return 403;
}
}

解读Nginx.conf中的信息

多域名绑定进行限制域名模式

server {
listen 10080 default_server;
server_name _;
return 403;
}

扩展名PHP可以配置PHP的支持

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:19001;
}

支持多站点的多个配置conf文件

include /usr/local/nginx/conf.d/*.conf;

多站点的某配置conf文件

WEBSVN站点的配置文件

server {
    listen       10080;
    server_name  svn.ly2016.club;
    root   /liuhome/nginx/websvn;
    index  index.html index.htm index.php;
    include /usr/local/nginx/conf/default.conf.d/*.conf;
    location / {
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

include /usr/local/nginx/conf.d/php.conf.bak;
}

Books站点的配置文件

server {
    listen       10080;
    server_name  book.ly2016.club;
    root   /liuhome/nginx/books;
    index  index.html index.htm index.php;
    include /usr/local/nginx/conf/default.conf.d/*.conf;
    location / {
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

include /usr/local/nginx/conf.d/php.conf.bak;

}

单独设置PHP语言文件

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:19001;
}

以上是关于centos6搭建智能Nginx服务器的主要内容,如果未能解决你的问题,请参考以下文章

centos6.8+nginx搭建简单的https服务器

centos6 LNMP的搭建(linux+nginx+mysql+php)

CentOS6.5搭建本地yum源(http方式) nginx

centos6.8+nginx+python2.7.13配置seafile私有云盘

centos6快速搭建nginx

阿里云centos6.9搭建fastDFS文件服务器