Webサーバー環境整備

パーミッションやオーナーを一括で変更する
qiita.com


CentOS 7 (5, 6) で "安定版 (最新版)" のNginxをインストールする方法
qiita.com


nginx

server {
    listen       80;
    server_name  example.com;

#    root   /opt/www;

    location / {
        index  index.php index.html;
    }

    location ~ ^/subdir/(img|css|js|files)/(.+)$ {
        root /usr/share/nginx/example.com/subdir/app/webroot;
        try_files /$1/$2 =404;
    }

#    location ~ ^/(.*)/(.+\.php) {
    location ~ ^/(.*)/ {
        root   /opt/www/$1/webroot;
        index  index.php index.html;
        try_files /$2 /$2/ /index.php?$2&$args;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include         fastcgi_params;
    }

#    location ~ ^/(.*)/ {
#        root   /opt/www/$1/webroot;
#        index  index.php index.html;
#        try_files index.php;
#        fastcgi_pass    127.0.0.1:9000;
#        fastcgi_index   index.php;
#        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
#        include         fastcgi_params;
#    }

#    location ~ \.php$ {
#        fastcgi_pass   127.0.0.1:9000;
#        fastcgi_index  index.php;
#        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
#        include        fastcgi_params;
#    }
}
server {
    listen       80;
    server_name  localhost;
    
    client_max_body_size 20M;
 
    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;
 
    location / {
        #root   /usr/share/nginx/html;
        root   /opt/www;
        index  index.html index.htm;
    }
	
    location ~ /(.*)/(img|css|js|files)/(.+)$ {
        root /opt/www/$1/webroot;
        try_files /$2/$3 =404;
    }
 
    # bad 
    # success
    location ~ /(.*)/(.*)$ {
        root /opt/www;
        index  index.php index.html;
        try_files /$1/$2 /$1/$2/ /$1/index.php?$2&$args;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_intercept_errors on;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
 
    location ~ \.php$ {
        root           /opt/www;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
 
}