nginx實戰(三) 靜態及php 環境配置

前言

系統環境:Centos 7
php : 5.6
nginx :openresty-1.13.6.2

環境安裝

nginx 見之間文章nginx實戰(一)

增加gzip 支持

cd openresty
./configure \
--with-http_gzip_static_module
gmake && gmake install

## 添加到nginx.conf 中
sed -r -i "/include conf./i\    include gzip.conf'" nginx.conf

php 5.6

yum -y install epel-release
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm && yum install -y --nogpgcheck --enablerepo=remi --enablerepo=remi-php56 \
php \
php-opcache \
php-devel \
php-mbstring \
php-mcrypt \
php-mysqlnd \
php-phpunit-PHPUnit \
php-pecl-xdebug \
php-pecl-xhprof \
php-gd \
php-ldap \
php-xml \
php-fpm \
php-bcmath \
php-gmp \
php-igbinary \
php-imagick \
php-memcache \
php-memcached \
php-mongo \
php-mongodb \
php-phalcon \
php-redis \
php-trace \
php-xmlrpc \
php-yaf

nginx php 配置


cat >/etc/nginx/conf/con.d/phpweb.conf<<EOF
server {
        listen       10081;
        #server_name  phpweb.savorof.org;
        access_log /opt/data/web/phpweb/phpweb.access.log  main;
        root   /opt/data/web/phpweb/webapps;
        index  index.html index.htm index.php;
        fastcgi_connect_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers   4 32k;
        fastcgi_busy_buffers_size 64k;
        fastcgi_temp_file_write_size 64k;
        #error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
        #    root   html;
        #}

        location / {
                if (!-e $request_filename) {
                    rewrite ^/(.*)$ /index.php/$1 last;
                    break;
            }
        }

        location ~ \.php {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
EOF

systemctl enable php-fpm
systemctl start php-fpm
systemctl restart nginx

常見問題

訪問報錯403 is forbidden

通常是三種情況:
一是缺少索引文件,指定的root 目錄 可能沒有 index.php 或index.html
二是權限問題, 確認nginx.conf 的user 參數指定的用戶對 root 的目錄有完全控制權限, chown -R user:user root 目錄
三是SELinux狀態 ,

setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
用最簡單的辦法解決每一個問題
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章