Nginx php 프레임 에서 의 설정

3771 단어
nginx 는 서로 다른 phop 프레임 워 크 의 설정 에 약간의 차이 가 있 습 니 다. 제 가 사용 하 는 몇 가 지 를 기록 합 니 다.
주: ubnutu 16.04 php 7.0 환경 에서
Thinkphp5
server {
 listen 80;
 server_name   url ;
 root /var/www/html/xxx/public/;

 add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?s=$uri&$args;
    }
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

   location ~ [^/]\.php(/|$) {
       set $path_info "";
       set $real_script_name $fastcgi_script_name;
           if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
                 set $real_script_name $1;
                 set $path_info $2;
        }
       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
       fastcgi_param SCRIPT_NAME $real_script_name;
       fastcgi_param PATH_INFO $path_info;
       include        fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }

}

Laravel5
server {
 listen 80;
 server_name utl;
 root /var/www/html/xxx/public/;

 add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }

}

LaravelS (larvale + swoole)
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}
upstream laravels {
     server ip:port weight=5 max_fails=3 fail_timeout=30s;
}
server {
    listen 80;
    server_name url;
    root "/var/www/html/xxx/public";
    autoindex off;
    index index.html index.htm;
    location / {
        try_files $uri @laravels;
    }
    location =/ws {
        proxy_http_version 1.1;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Real-PORT $remote_port;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header Server-Protocol $server_protocol;
        proxy_set_header Server-Name $server_name;
        proxy_set_header Server-Addr $server_addr;
        proxy_set_header Server-Port $server_port;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_pass http://laravels;
    }
    location @laravels {
        proxy_http_version 1.1;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Real-PORT $remote_port;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header Scheme $scheme;
        proxy_set_header Server-Protocol $server_protocol;
        proxy_set_header Server-Name $server_name;
        proxy_set_header Server-Addr $server_addr;
        proxy_set_header Server-Port $server_port;
        proxy_pass http://laravels;
    }
}

좋은 웹페이지 즐겨찾기