Linux下安装nginx, php, php-fpm并配置
環(huán)境: Fedora20
?
目標(biāo): 在Fedora20上安裝好nginx服務(wù)器,并可正確解析php文件
?
1. 安裝:
yum makecache
yum install nginx php php-fpm
?
2. nginx的配置
按默認(rèn)配置(網(wǎng)站根目錄路徑:/usr/share/nginx/html),一般也是OK的。通過瀏覽器打開http://localhost來看,如果能正常顯示網(wǎng)頁(yè),就OK了。
還可以通過"nginx -t“ 來檢測(cè)
3. 修改,我將網(wǎng)站根目錄移到了/home/zcm/program/web下,導(dǎo)致出現(xiàn)了一系列的問題,現(xiàn)帖出完整配置(/etc/nginx/nginx.conf),以備將來對(duì)照
# 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. 接下來才是重點(diǎn)
如果僅做了以上3步,訪問html等非php文件可能已經(jīng)沒問題了,但是要訪問.php文件,可能還不行,因?yàn)樯婕暗綑?quán)限問題。
4.1 需要給/home/zcm 加上rx權(quán)限:chmod +rx /home/zcm
4.2 對(duì)應(yīng)的.php文件要具有r權(quán)限.
?
5. 最后補(bǔ)充一點(diǎn)
Linux下的防火墻默認(rèn)阻擋了許多的協(xié)議和端口,如果在windows上ping不通或telnet不到指定端口,請(qǐng)一定要考慮下防火墻的問題。
?
完成以上配置,應(yīng)該就差不多了。如果實(shí)在是還有其他問題,可以仔細(xì)看下日志: /var/log/nginx/*
總結(jié)
以上是生活随笔為你收集整理的Linux下安装nginx, php, php-fpm并配置的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode:Count Prime
- 下一篇: linux基础知识个人总结