개발 꿀팁/PHP

nginx 설정 php 프로젝트 프로필!

Jammie 2022. 7. 19. 14:36
반응형

싱글 php:

server
        {
            listen 80 ;
            #listen [::]:80 default_server ipv6only=on;
            server_name www.s13.cn;
            index index.html index.htm index.php;
            root   /www/crm/FLY-CRM/Crm;
            client_max_body_size 100m;
            #error_page   404   /404.html;
 
            # Deny access to PHP files in specific directory
            #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
            #if (!-e $request_filename)
            #    {
            #        rewrite ^/(.*)$ /index.php?s=$1 last;
            #    }
 
            #include enable-php.conf;
            location / {
                try_files $uri $uri/ /index.php?s=$uri&$args;
            }
            location ~ [^/]\.php(/|$)
                {
                    # comment try_files $uri =404; to enable pathinfo
                    try_files $uri =404;
                    fastcgi_pass  127.0.0.1:9000;
                    fastcgi_index index.php;
                    include fastcgi.conf;
                    #include pathinfo.conf;
                    set $real_script_name $fastcgi_script_name;
                    if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
                        set $real_script_name $1;
                        set $path_info $2;
                    }
                    fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
                    fastcgi_param SCRIPT_NAME $real_script_name;
                    fastcgi_param PATH_INFO $path_info;
		    fastcgi_param APPLICATION_ENV 'development';
                }
            #location /nginx_status
            #{
            #    stub_status on;
            #    access_log   off;
            #}
 
            location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
            {
                expires      30d;
            }
 
            location ~ .*\.(js|css)?$
            {
                expires      12h;
            }
 
            location ~ /.well-known {
                allow all;
            }
 
            location ~ /\.
            {
                deny all;
            }
 
            access_log  /var/log/nginx/fly-crm.log;
        }

다중 인스턴스 php:

server {
 
    listen 80;
    listen [::]:80;
 
    server_name qtalk-api.sincewin.cn;
    root /www/;
    index   index.php index.html index.htm  ;
    client_max_body_size 200m;
 
    location ~ ^/(m|fission|basecommon|mobile)/  {
  ##add_header Access-Control-Allow-Origin $http_origin;
  ##add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
  ##add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
      ## add_header 'Access-Control-Allow-Credentials' 'true';
                 root /www/;
                 #return 200 $uri;
                 #add_header X-debug-message "god" always;
                 #try_files $uri $uri/ /index.php/$is_args$args;
                 try_files $uri $uri/ /index.pmhp?$query_string;
            }
 
            location ~ \.pmhp(/|$) {
  add_header Access-Control-Allow-Origin $http_origin;
  add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
  add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
       add_header 'Access-Control-Allow-Credentials' 'true';
                 root /www;
                 fastcgi_pass 127.0.0.1:9001;
                 include fastcgi.conf;
                 fastcgi_param SCRIPT_FILENAME $document_root/index.php;
             }
 
             location ^~ /api/ {
  add_header Access-Control-Allow-Origin $http_origin;
  add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
  add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
       add_header 'Access-Control-Allow-Credentials' 'true';
                 root /www;
                 #add_header X-debug-message "god" always;
                 #try_files $uri $uri/ /index.php/$is_args$args;
                 try_files $uri $uri/ /index.pahp?$query_string;
            }
 
            location ~ \.pahp(/|$) {
  add_header Access-Control-Allow-Origin $http_origin;
  add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
  add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
       add_header 'Access-Control-Allow-Credentials' 'true';
                 root /www/qtalk_api/qtalk_api/public/;
                 fastcgi_pass 127.0.0.1:9001;
                 include fastcgi.conf;
                 fastcgi_param SCRIPT_FILENAME $document_root/index.php;
             }
 
 
    location / {
         try_files $uri  $uri/ /index.php$is_args$args;
    }
 
    location ~ \.php$ {
	root /www/qtalk_api/qtalk_api/public;
        fastcgi_pass 127.0.0.1:9001;
        fastcgi_index index.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
 
    location ~ /\.ht {
        deny all;
    }
 
    error_log /var/log/nginx/qtalk_api_error.log;
    access_log /var/log/nginx/qtalk_api_access.log;
}

##add_header Access-Control-Allow-Origin $http_origin;
##add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept;
##add_header Access-Control-Allow-Methods "GET, POST, OPTIONS;
## add_header 'Access-Control-Allow-Credentials' 'true'; 이것들은 교차 도메인 설정입니다!!!

반응형