下载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; server_name _; 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;
}