nginx安装php-fpm,Linux下安装nginx, php, php-fpm并配置

环境: Fedora20

目标: 在Fedora20上安装好nginx服务器,并可正确解析php文件

1. 安装:

yum makecache

yum install nginx php php-fpm

2. nginx的配置

按默认配置(网站根目录路径:/usr/share/nginx/html),一般也是OK的。通过浏览器打开http://localhost来看,如果能正常显示网页,就OK了。

还可以通过"nginx -t“ 来检测

3. 修改,我将网站根目录移到了/home/zcm/program/web下,导致出现了一系列的问题,现帖出完整配置(/etc/nginx/nginx.conf),以备将来对照

# For more information on configuration, see:

# * Official English Documentation: http://nginx.org/en/docs/

# * Official Russian Documentation: http://nginx.org/ru/docs/

#user nginx;

user zcm;

worker_processes 1;

error_log /var/log/nginx/error.log;

#error_log /var/log/nginx/error.log notice;

#error_log /var/log/nginx/error.log info;

pid /run/nginx.pid;

events {

worker_connections 1024;

}

http {

include /etc/nginx/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"';

access_log /var/log/nginx/access.log main;

sendfile on;

#tcp_nopush on;

#keepalive_timeout 0;

keepalive_timeout 65;

#gzip on;

index index.html index.htm;

# Load modular configuration files from the /etc/nginx/conf.d directory.

# See http://nginx.org/en/docs/ngx_core_module.html#include

# for more information.

include /etc/nginx/conf.d/*.conf;

server {

listen 80 default_server;

server_name localhost;

root/home/zcm/program/web;

#charset koi8-r;

#access_log /var/log/nginx/host.access.log main;

# Load configuration files for the default server block.

include /etc/nginx/default.d/*.conf;

location / {

}

# redirect server error pages to the static page /40x.html

#

error_page 404 /404.html;

location = /40x.html {

}

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ \.php$ {

#root /home/zcm/program/web;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

}

}

4. 接下来才是重点

如果仅做了以上3步,访问html等非php文件可能已经没问题了,但是要访问.php文件,可能还不行,因为涉及到权限问题。

4.1 需要给/home/zcm 加上rx权限:chmod +rx /home/zcm

4.2 对应的.php文件要具有r权限.

5. 最后补充一点

Linux下的防火墙默认阻挡了许多的协议和端口,如果在windows上ping不通或telnet不到指定端口,请一定要考虑下防火墙的问题。

完成以上配置,应该就差不多了。如果实在是还有其他问题,可以仔细看下日志: /var/log/nginx/*

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值