2016年7月31日 星期日

在 CentOS7/RHEL7 上架設 Nginx Web Server(二)

設定目標:
  • 在 Centos 7 上架設 Nginx 1.10.1 + Php 7.0 (Remi) 套件!
Nginx Web Server 快速設定流程:
  1. 編寫最新的 Nginx 套件位置:
    #vim /etc/yum.repos.d/nginx.repo
    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/centos/7/$basearch/
    gpgcheck=0
    enabled=1
    
  2. 安裝最新的 Nginx 套件:
    # yum install nginx-*
    
  3. 開啟防火牆:
    # firewall-cmd --permanent --add-service=http
    # firewall-cmd --reload
    
  4. 啟動 Nginx 服務:
    #systemctl enable nginx.service
    #systemctl start nginx.service
    #systemctl status nginx.service -l
    
PHP 7 (Remi) 快速設定流程:
  1. 安裝 Remi 套件的 repo 檔案:
    #wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
    #rpm -Uvh remi-release-7.rpm
    
  2. 安裝 PHP 7.0 套件:
    # yum install php70 php70-php-fpm php70-php-mbstring php70-php-mcrypt php70-php-gd
    
  3. 修改 php-fpm 設定檔:
    #vim /etc/opt/remi/php70/php-fpm.d/www.conf
    user = nginx
    group = nginx
    listen = /var/run/php-fpm.sock
    listen.owner = nginx
    listen.group = nginx
    listen.mode = 0666
    
  4. 啟動 php-fpm 服務:
    # systemctl enable php70-php-fpm.service
    # systemctl start php70-php-fpm.service
    
  5. 修改 Nginx 設定檔:
    # vim /etc/nginx/conf.d/default.conf
    (修改下列設定:)
        access_log  /var/log/nginx/access.log  main;
        error_log /var/log/nginx/error.log warn;
        
        location / {
            root   /usr/share/nginx/html;
            index  index.php index.html index.htm;
        }
    
        location ~ \.php$ {
            root           /usr/share/nginx/html;
        #    fastcgi_pass   127.0.0.1:9000;
            fastcgi_pass unix:/var/run/php-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
        :
        :
    
  6. 動新啟動 nginx:
    #systemctl restart nginx.service
    
  7. 開啟 SELinux 設定:
    #setsebool -P httpd_can_network_connect on