GVKun编程网logo

nginx 部署:在cygwin下部署PHP环境,mssql+PHP +nginx+freetds(nginx部署windows)

1

最近很多小伙伴都在问nginx部署:在cygwin下部署PHP环境,mssql+PHP+nginx+freetds和nginx部署windows这两个问题,那么本篇文章就来给大家详细解答一下,同时本文

最近很多小伙伴都在问nginx 部署:在cygwin下部署PHP环境,mssql+PHP +nginx+freetdsnginx部署windows这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展12.13 Nginx 防盗链 12.14 Nginx 访问控制 12.15 Nginx 解析 php 相关配置 12.16 Nginx 代理、6 月 11 日任务 Nginx 防盗链、Nginx 访问控制、Nginx 解析 php 相关配置、Nginx 代理、centos + php+ unixodbc + FreeTDS 配置、FreeTDS - 在 amazon linux docker 平台上使用 Docker 的 tsql 连接失败等相关知识,下面开始了哦!

本文目录一览:

nginx 部署:在cygwin下部署PHP环境,mssql+PHP +nginx+freetds(nginx部署windows)

nginx 部署:在cygwin下部署PHP环境,mssql+PHP +nginx+freetds(nginx部署windows)


因为公司的环境是在linux下,所以想在自己的机器上搭建个模仿linux的环境
环境为linux +mssql+PHP +nginx+freetds
于是就想到了cygwin
去http://www.cygwin.com 下载setup.exe
然后安装,安装方法网上一大堆,主要是要安装好GCC相关的东西,我是把 devel目录下的东西都安装上
默认是default 点击下default 可以变成install
下载nginx
http://nginx.org/download/nginx-1.2.6.tar.gz
安装
tar zxvf nginx-1.2.6.tar.gz
cd nginx-1.2.6
./configure
make && make install
如果没有提示出错的话就是安装好了,进入默认的安装目录 cd /usr/local/nginx
cd sbin
如果有nginx.exe就说明安装成功了 要启动nginx ./nginx.exe就行了
就可以用ps -efgrep nginx看到进程了
然后是安装freetds
去http://www.freetds.org/下载freetds
ftp://ftp.freetds.org/pub/freetds/stable/freetds-stable.tgz
安装跟nginx一样
tar freetds-stable.tgz
cd freetds-0.91
./configure
make && make install
然后安装PHP
下载PHP
http://us1.php.net/distributions/php-5.4.11.tar.gz

tar php-5.4.11.tar.gz
cd php-5.4.11
./configure --prefix=/usr/local/php --enable-mbstring --enable-sockets --with-config-file-path=/usr/local/php --with-mssql=/usr/local/freetds --enable-fpm
make && make install
一些警告忽略掉,然后启动PHP
cd /usr/local/php/sbin/
./php-fpm.exe 就可以启动php fpm了
但是用CI框架 发现
$_SERVER[''SCRIPT_NAME'']获取URL的路径有问题

正常$_SERVER[''REQUEST_URI''] 获取的是/index.php/welcome
$_SERVER[''SCRIPT_NAME''] 获取的应该是/index.php
但是我的cygwin获取的是 $_SERVER[''REQUEST_URI''] 获取的是/index.php/welcome
$_SERVER[''SCRIPT_NAME''] 获取的应该是/index.php/welcome
两个是一样的,这样就有问题了,
还有一个是下载了PHPredis安装也没出错,但是 在php.ini加扩展时总是提示出错
NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library ''/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/redisa'' - Exec format error in Unknown on line 0

怀疑是不是PHP没安装好,因为有很多警告,不知道有没有发生过错误,待重新安装一次确认下
安装redis时 会报redis.c:1xxx: error: `SA_ONSTACK'' undeclared (first use in this function) 的错误
因为cygwin里没有定义SA_ONSTACK
在sys/resource.h中加上
ifndef SA_ONSTACK
define SA_ONSTACK 0
endif 本文链接http://www.cxybl.com/html/wlbc/Php/20130601/38184.html



12.13 Nginx 防盗链 12.14 Nginx 访问控制 12.15 Nginx 解析 php 相关配置 12.16 Nginx 代理

12.13 Nginx 防盗链 12.14 Nginx 访问控制 12.15 Nginx 解析 php 相关配置 12.16 Nginx 代理

12.13 Nginx 防盗链

因为该配置也使用 location 板块,所以本节可结合日志管理(不记录和过期时间)一起配置:

[root@cham002 ~]# vim /usr/local/nginx/conf/vhost/test.com.conf 

location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$
{
    expires 7d;
    valid_referers none blocked server_names  *.test.com ;
#定义referer白名单
    if ($invalid_referer) {
        return 403;
#if函数的意思是:如果不是白名单内的域名,返回值:403
    }
    access_log off;
}

说明: “location ~* ^.+” 在此 0“ * ” 的作用是后面匹配的内容不区分大小写。

检测及测试

[root@cham002 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@cham002 ~]# /usr/local/nginx/sbin/nginx -s reload
[root@cham002 ~]# ls /data/wwwroot/test.com/
1.gif  2.js  admin  index.html
[root@cham002 ~]# curl -e "http://www.baidu.com/1.txt" -x127.0.0.1:80 -I test.com/1.gif
HTTP/1.1 403 Forbidden
Server: nginx/1.12.1
Date: Wed, 03 Jan 2018 13:54:39 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive

[root@cham002 ~]# curl -e "http://www.test.com/1.txt" -x127.0.0.1:80 -I test.com/1.gif
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Wed, 03 Jan 2018 13:55:14 GMT
Content-Type: image/gif
Content-Length: 32
Last-Modified: Wed, 03 Jan 2018 13:34:18 GMT
Connection: keep-alive
ETag: "5a4cdbda-20"
Expires: Wed, 10 Jan 2018 13:55:14 GMT
Cache-Control: max-age=604800
Accept-Ranges: bytes

即,使用非白名单内的 referer 进行访问,被拒绝!!!

 

12.14 Nginx 访问控制

需求:访问 /admin/ 目录的请求,只允许几个指定 IP 通过,配置如下:

[root@cham002 ~]# vim /usr/local/nginx/conf/vhost/test.com.conf 
server
{
    listen 80;
    server_name test.com test2.com test3.com;
    index index.html index.htm index.php;
    root /data/wwwroot/test.com;
    if ($host != ''test.com'' ) {
        rewrite  ^/(.*)$  http://test.com/$1  permanent;
    }
   # location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
   # {
   #       expires      7d;
   #       access_log off;
   # }
location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$
{
    expires 7d;
    valid_referers none blocked server_names  *.test.com ;
    if ($invalid_referer) {
        return 403;
    }
    access_log off;
}


    location ~ .*\.(js|css)$
    {
          expires      12h;
          access_log off;
    }
    location /admin/
    {
       allow 127.0.0.1;
       allow 192.168.230.135;
       deny all;
#设置IP白名单
    }

    access_log /tmp/test.com.log cham;
}


[root@cham002 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@cham002 ~]# /usr/local/nginx/sbin/nginx -s reload

测试 (针对目录的)


[root@cham002 ~]# curl -e "http://www.baidu.com/1.txt" -x127.0.0.1:80 -I test.com/admin/
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Thu, 04 Jan 2018 07:59:16 GMT
Content-Type: text/html
Content-Length: 20
Last-Modified: Wed, 03 Jan 2018 08:50:53 GMT
Connection: keep-alive
ETag: "5a4c996d-14"
Accept-Ranges: bytes

[root@cham002 ~]# curl -x192.168.230.150:80 -I test.com/admin/
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Thu, 04 Jan 2018 08:01:00 GMT
Content-Type: text/html
Content-Length: 20
Last-Modified: Wed, 03 Jan 2018 08:50:53 GMT
Connection: keep-alive
ETag: "5a4c996d-14"
Accept-Ranges: bytes

[root@cham002 ~]# curl -x192.168.230.135:80 -I test.com/admin/
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Thu, 04 Jan 2018 08:01:14 GMT
Content-Type: text/html
Content-Length: 20
Last-Modified: Wed, 03 Jan 2018 08:50:53 GMT
Connection: keep-alive
ETag: "5a4c996d-14"
Accept-Ranges: bytes

[root@cham002 ~]# cat /tmp/test.com.log
127.0.0.1 - [03/Jan/2018:21:35:36 +0800] test.com "/index.html" 200 "-" "curl/7.29.0"
127.0.0.1 - [04/Jan/2018:15:59:16 +0800] test.com "/admin/" 200 "http://www.baidu.com/1.txt" "curl/7.29.0"
192.168.230.135 - [04/Jan/2018:16:01:00 +0800] test.com "/admin/" 200 "-" "curl/7.29.0"
192.168.230.135 - [04/Jan/2018:16:01:14 +0800] test.com "/admin/" 200 "-" "curl/7.29.0"
[root@cham002 ~]# curl -x192.168.230.150:80 -I test.com/admin/
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Thu, 04 Jan 2018 08:01:37 GMT
Content-Type: text/html
Content-Length: 20
Last-Modified: Wed, 03 Jan 2018 08:50:53 GMT
Connection: keep-alive
ETag: "5a4c996d-14"
Accept-Ranges: bytes

[root@cham002 ~]# cat /tmp/test.com.log
127.0.0.1 - [03/Jan/2018:21:35:36 +0800] test.com "/index.html" 200 "-" "curl/7.29.0"
127.0.0.1 - [04/Jan/2018:15:59:16 +0800] test.com "/admin/" 200 "http://www.baidu.com/1.txt" "curl/7.29.0"
192.168.230.135 - [04/Jan/2018:16:01:00 +0800] test.com "/admin/" 200 "-" "curl/7.29.0"
192.168.230.135 - [04/Jan/2018:16:01:14 +0800] test.com "/admin/" 200 "-" "curl/7.29.0"
192.168.230.135 - [04/Jan/2018:16:01:37 +0800] test.com "/admin/" 200 "-" "curl/7.29.0"

[root@cham002 ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.230.135  netmask 255.255.255.0  broadcast 192.168.230.255
        inet6 fe80::6f15:52d3:ebeb:e193  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b6:9f:e3  txqueuelen 1000  (Ethernet)
        RX packets 96831  bytes 41894507 (39.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 60974  bytes 20136998 (19.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.230.150  netmask 255.255.255.0  broadcast 192.168.230.255
        ether 00:0c:29:b6:9f:e3  txqueuelen 1000  (Ethernet)

ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.1  netmask 255.255.255.0  broadcast 192.168.100.255
        inet6 fe80::1801:cbbb:ebcc:89a3  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b6:9f:ed  txqueuelen 1000  (Ethernet)
        RX packets 3  bytes 746 (746.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 81  bytes 6462 (6.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 1363  bytes 1359483 (1.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1363  bytes 1359483 (1.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@cham002 ~]# curl -x192.168.100.1:80 test.com/admin/
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.12.1</center>
</body>
</html>

[root@cham002 ~]# cat /tmp/test.com.log
127.0.0.1 - [03/Jan/2018:21:35:36 +0800] test.com "/index.html" 200 "-" "curl/7.29.0"
127.0.0.1 - [04/Jan/2018:15:59:16 +0800] test.com "/admin/" 200 "http://www.baidu.com/1.txt" "curl/7.29.0"
192.168.230.135 - [04/Jan/2018:16:01:00 +0800] test.com "/admin/" 200 "-" "curl/7.29.0"
192.168.230.135 - [04/Jan/2018:16:01:14 +0800] test.com "/admin/" 200 "-" "curl/7.29.0"
192.168.230.135 - [04/Jan/2018:16:01:37 +0800] test.com "/admin/" 200 "-" "curl/7.29.0"
192.168.100.1 - [04/Jan/2018:16:05:14 +0800] test.com "/admin/" 403 "-" "curl/7.29.0

 

访问控制(针对正则匹配)

[root@cham002 ~]# vim /usr/local/nginx/conf/vhost/test.com.conf 
server
{
    listen 80;
    server_name test.com test2.com test3.com;
    index index.html index.htm index.php;
    root /data/wwwroot/test.com;
    if ($host != ''test.com'' ) {
        rewrite  ^/(.*)$  http://test.com/$1  permanent;
    }
   # location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
   # {
   #       expires      7d;
   #       access_log off;
   # }
location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$
{
    expires 7d;
    valid_referers none blocked server_names  *.test.com ;
    if ($invalid_referer) {
        return 403;
    }
    access_log off;
}


    location ~ .*\.(js|css)$
    {
          expires      12h;
          access_log off;
    }
    location /admin/
    {
       allow 127.0.0.1;
       allow 192.168.230.135;
       deny all;
    }

    location ~ .*(upload|image)/.*\.php$
    {
        deny all;
    }


    access_log /tmp/test.com.log cham;
}

[root@cham002 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@cham002 ~]# /usr/local/nginx/sbin/nginx -s reload
[root@cham002 ~]# mkdir /data/wwwroot/test.com/upload
[root@cham002 ~]# echo "11111" > /data/wwwroot/test.com/upload/1.php

测试

[root@cham002 ~]# curl -x127.0.0.1:80 test.com/upload/1.php
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.12.1</center>
</body>
</html>


[root@cham002 ~]# curl -x127.0.0.1:80 test.com/upload/1.txt
11111
看日志
[root@cham002 ~]# cat /tmp/test.com.log
127.0.0.1 - [03/Jan/2018:21:35:36 +0800] test.com "/index.html" 200 "-" "curl/7.29.0"
127.0.0.1 - [04/Jan/2018:15:59:16 +0800] test.com "/admin/" 200 "http://www.baidu.com/1.txt" "curl/7.29.0"
192.168.230.135 - [04/Jan/2018:16:01:00 +0800] test.com "/admin/" 200 "-" "curl/7.29.0"
192.168.230.135 - [04/Jan/2018:16:01:14 +0800] test.com "/admin/" 200 "-" "curl/7.29.0"
192.168.230.135 - [04/Jan/2018:16:01:37 +0800] test.com "/admin/" 200 "-" "curl/7.29.0"
192.168.100.1 - [04/Jan/2018:16:05:14 +0800] test.com "/admin/" 403 "-" "curl/7.29.0"
127.0.0.1 - [04/Jan/2018:16:15:46 +0800] test.com "/upload/1.php" 403 "-" "curl/7.29.0"
127.0.0.1 - [04/Jan/2018:16:16:46 +0800] test.com "/upload/1.txt" 200 "-" "curl/7.29.0"

针对 user_agent 限制

server
{
    listen 80;
    server_name test.com test2.com test3.com;
    index index.html index.htm index.php;
    root /data/wwwroot/test.com;
    if ($host != ''test.com'' ) {
        rewrite  ^/(.*)$  http://test.com/$1  permanent;
    }
   # location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
   # {
   #       expires      7d;
   #       access_log off;
   # }
location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$
{
    expires 7d;
    valid_referers none blocked server_names  *.test.com ;
    if ($invalid_referer) {
        return 403;
    }
    access_log off;
}


    location ~ .*\.(js|css)$
    {
          expires      12h;
          access_log off;
    }
    location /admin/
    {
       allow 127.0.0.1;
       allow 192.168.230.135;
       deny all;
    }

    location ~ .*(upload|image)/.*\.php$
    {
        deny all;
    }
    
    if ($http_user_agent ~ ''Spider/3.0|YoudaoBot|Tomato'')
    {
      return 403;
    }



    access_log /tmp/test.com.log cham;
}
[root@cham002 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@cham002 ~]# /usr/local/nginx/sbin/nginx -s reload
[root@cham002 ~]# curl -x127.0.0.1:80 test.com/upload/1.txt -I
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Thu, 04 Jan 2018 08:22:45 GMT
Content-Type: text/plain
Content-Length: 6
Last-Modified: Thu, 04 Jan 2018 08:16:39 GMT
Connection: keep-alive
ETag: "5a4de2e7-6"
Accept-Ranges: bytes

[root@cham002 ~]# curl -A "Tomatodsfsdf" -x127.0.0.1:80 test.com/upload/1.txt -I
HTTP/1.1 403 Forbidden
Server: nginx/1.12.1
Date: Thu, 04 Jan 2018 08:23:37 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive

说明: deny all 和 return 403 效果一样

 

12.15 Nginx 解析 PHP 相关配置

核心配置:
[root@cham002 ~]# vim /usr/local/nginx/conf/vhost/test.com.conf 

 location ~ \.php$
    {
        include fastcgi_params;
        #fastcgi_pass unix:/tmp/php-fcgi.sock;
        fastcgi_pass 127.0.0.1:9000;
##fastcgi_pass两种监听格式,但是要保证Nginx和php-fpm中格式一致
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name;
    }

[root@cham002 ~]# cat /usr/local/php-fpm/etc/php-fpm.conf
[global]
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
[www]
#listen = /tmp/php-fcgi.sock
listen = 127.0.0.1:9000
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024

[root@cham002 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@cham002 ~]# /usr/local/nginx/sbin/nginx -s reload
[root@cham002 ~]# /etc/init.d/php-fpm reload
Reload service php-fpm  done

[root@cham002 ~]# curl -x 127.0.0.1:80 test.com/3.php -I
HTTP/1.1 200 OK
Server: nginx/1.12.1
Date: Thu, 04 Jan 2018 10:44:25 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.6.30

 

注: 在此注意两点,fastcgi_pass 有两种格式,但是无论使用哪种格式都有保证 Nginx 和 php-fpm 中格式一致,否则会报错 502;fastcgi _param SCRIPT _FILENAME 所在行的路径要和 root 路径一致!

 

12.16 Nginx 代理

Nginx 代理是一种反向代理。反向代理(Reverse Proxy)方式是指以代理服务器来接受 Internet 上的连接请求,然后将请求转发给内部网络上的服务器;并将从服务器上得到的结果返回给 Internet 上请求连接的客户端,此时代理服务器对外就表现为一个服务器。

 

工作原理

Nginx 代理是在一台代理服务器中自定义一个域名,该域名指向一个 IP,然后将用户的请求通过这台代理服务器访问指定的 IP 所对应的 web 服务器。

graph LR
用户-->代理服务器
代理服务器-->用户
代理服务器-->web服务器
web服务器-->代理服务器
[root@cham002 ~]# cd /usr/local/nginx/conf/vhost
[root@cham002 vhost]# vim proxy.conf 

server
{
    listen 80;
    server_name ask.apelearn.com;
 #定义域名(一般和被代理ip的域名保持一致)

    location /
    {
        proxy_pass      http://121.201.9.155/;
#指定被代理(被访问)的IP(web服务器IP)
        proxy_set_header Host   $host;
#$host指的是代理服务器的servername(也是被代理IP的域名)
        proxy_set_header X-Real-IP      $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

说明: 因为该虚拟主机只用作代理服务器,不需要访问本地文件,所以不需要设置根目录。

没有设置代理前
[root@cham002 vhost]# curl -x127.0.0.1:80 ask.apelearn.com/robots.txt
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.12.1</center>
</body>
</html>
[root@cham002 vhost]# 

[root@cham002 vhost]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@cham002 vhost]# /usr/local/nginx/sbin/nginx -s reload
设置代理后
[root@cham002 vhost]# curl -x127.0.0.1:80 ask.apelearn.com/robots.txt
#
# robots.txt for MiWen
#

User-agent: *

Disallow: /?/admin/
Disallow: /?/people/
Disallow: /?/question/
Disallow: /account/
Disallow: /app/
Disallow: /cache/
Disallow: /install/
Disallow: /models/
Disallow: /crond/run/
Disallow: /search/
Disallow: /static/
Disallow: /setting/
Disallow: /system/
Disallow: /tmp/
Disallow: /themes/
Disallow: /uploads/
Disallow: /url-*
Disallow: /views/
Disallow: /*/ajax/[root@cham002 vhost]# 

 

6 月 11 日任务 Nginx 防盗链、Nginx 访问控制、Nginx 解析 php 相关配置、Nginx 代理

6 月 11 日任务 Nginx 防盗链、Nginx 访问控制、Nginx 解析 php 相关配置、Nginx 代理

12.13 Nginx 防盗链

修改配置文件

location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|doc|pdf|gz|bz2|jpeg|bmp|xls)$
{
expires 7d;
valid_referers none blocked server_names  *.abc.com ;
if ($invalid_referer) {
return 403;
}
access_log off;
}

测试: 

curl -e "http://www.abc.com/" -x127.0.0.1:80 -I abc.com/1.jpg

12.14 Nginx 访问控制

修改配置文件  

#按目录匹配

location /
{
allow 127.0.0.1;
deny all;
}

#可以匹配正则

location ~ .*(upload|image)/.*\.php$     

{

        deny all;

}

#根据 user_agent 限制

if ($http_user_agent ~* ''Spider/3.0|YoudaoBot|Tomato'')   // 匹配符号后面 +* 忽略大小写

{

      return 403;

}

 deny all 和 return 403 效果一样

 

12.15 Nginx 解析 php 相关配置

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;

fastcgi_pass 配置对应的参数  是 sock  还是 ip  否则 502 错误

listen.mode = 666     监听 sock 不定义 mode sock 文件权限 440  

12.16 Nginx 代理

1. 新建配置文件  proxy.conf

server
{
    listen 80;
    server_name 111.com;      // 本机域名
    location /
    {
        proxy_pass      http://106.39.167.118:80/;     // 目标服务器
        proxy_set_header Host   $host;
        proxy_set_header X-Real-IP      $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

 

 

 

centos + php+ unixodbc + FreeTDS 配置

centos + php+ unixodbc + FreeTDS 配置

linux 上 php 连 MSSQL, 使用 unixodbc + FreeTDS

安装步骤:

安装 unixODBC

yum install unixODBC
yum install unixODBC-devel

安装 FreeTDS


./configure --with-tdsver=8.0 --prefix=/usr/local/freetds --enable-msdblib --with-gnu-ld --enable-shared --enable-static

make

make install

vi /usr/local/freetds/etc/freetds.conf

[PPCSERVER]
host = 192.168.2.120
port = 1433
tds version = 8.0
client charset = UTF-8

测试连接

/usr/local/freetds/bin/tsql -S PPCMSSQL -U 7230 -P 7230


vi /etc/odbcinst.ini

[FREETDS]
Description     = ODBC of FreeTDS for MS SQL 2000
Driver          = /usr/local/freetds/lib/libtdsodbc.so
Setup           = /usr/local/freetds/lib/libtds.so
FileUsage       = 1


vi /etc/odbc.ini

[ODBC Data Sources]
ppc= ppc sql server

[PPCMSSQL]
Driver          = FREETDS
Description     = ppc sql server
Trace           = No
Servername      = PPCSERVER
Database        = 7230

测试连接

isql -v PPCMSSQL 7230 7230





FreeTDS - 在 amazon linux docker 平台上使用 Docker 的 tsql 连接失败

FreeTDS - 在 amazon linux docker 平台上使用 Docker 的 tsql 连接失败

如何解决FreeTDS - 在 amazon linux docker 平台上使用 Docker 的 tsql 连接失败

我已经构建了一个使用 FreeTDS 连接到 MSsql 服务器的 docker 镜像 test-image:latest。因此,当我在本地或使用此映像在 ec2 实例上运行容器时,连接成功。

  1. $ tsql -S <server> -U <username> -P <password>
  2. locale is "C"
  3. locale charset is "ANSI_X3.4-1968"
  4. using default charset "ISO-8859-1"
  5. 1>

但是,当我尝试使用 aws beanstalk docker 平台基于此映像启动应用程序时,tsql 连接失败。 Beanstalk 有一个在 Amazon Linux 2 上运行的 docker platform。当我登录到相应的 ec2 实例时,从正在运行的容器(从 tsql 创建)内部运行 test-image:latest,我得到递增的数字。我相信当实例无法连接到 <server> 时会发生这种情况。

  1. $ tsql -S <server_name> -U <username> -P <password>
  2. locale is "C"
  3. locale charset is "ANSI_X3.4-1968"
  4. using default charset "ISO-8859-1"
  5. 1
  6. 2
  7. 3
  8. and so on

如果我创建一个新的 Amazon Linux 2 实例,在其上安装 docker 并运行此实验,则 tsql 连接有效。

当 Beanstalk 创建该实例时,同一个 docker 映像在其他情况下都可以正常工作,但它却无法正常工作,这可能是什么原因?

注意:我将在 <server> 的安全组中运行 docker 容器的实例列入白名单。我已经通过 ping 服务器测试了连接

今天关于nginx 部署:在cygwin下部署PHP环境,mssql+PHP +nginx+freetdsnginx部署windows的介绍到此结束,谢谢您的阅读,有关12.13 Nginx 防盗链 12.14 Nginx 访问控制 12.15 Nginx 解析 php 相关配置 12.16 Nginx 代理、6 月 11 日任务 Nginx 防盗链、Nginx 访问控制、Nginx 解析 php 相关配置、Nginx 代理、centos + php+ unixodbc + FreeTDS 配置、FreeTDS - 在 amazon linux docker 平台上使用 Docker 的 tsql 连接失败等更多相关知识的信息可以在本站进行查询。

本文标签: