Linux下安装nginx, php, 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/*
總結
以上是生活随笔為你收集整理的Linux下安装nginx, php, php-fpm并配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode:Count Prime
- 下一篇: php7.2 event扩展php_so