Nginx+php 搭建Thinkphp服务支持URL_MODEL全模式

  1. 以下部署中nginx配置支持thinkphp的URL_MODEL全模式

    ‘URL_MODEL’ => 1, // URL访问模式,可选参数0、1、2、3,代表以下四种模式:// 0 (普通模式); 1 (PATHINFO 模式); 2 (REWRITE 模式); 3 (兼容模式) 默认为PATHINFO 模式

  2. 安装Nginx(1.16.1)

    • 下载:wget http://nginx.org/download/nginx-1.16.1.tar.gz

    • 安装依赖

      • apt-get install gcc g++ autoconf automake
      • apt-get install zlib1g-dev openssl libssl-dev libpcre3 libpcre3-dev
    • 编译安装
      tar xvf nginx-1.16.1.tar.gz
      cd nginx-1.16.1
      ./configure --with-stream
      make
      make install
      ldconfig

    • 配置nginx.conf
      vi /usr/local/nginx/conf/nginx.conf #直接替换所有内容

         user  root;
         worker_processes  auto;
      
         #error_log  logs/error.log;
         #error_log  logs/error.log  notice;
         #error_log  logs/error.log  info;
      
         #pid        logs/nginx.pid;
      
      
         events {
         	use epoll;
         	worker_connections  51200;
         	multi_accept on;
         }
      
      
         http {
         	include       mime.types;
         	default_type  application/octet-stream;
         	
         	server_names_hash_bucket_size 128;
         	client_header_buffer_size 32k;
         	large_client_header_buffers 4 32k;
         	client_max_body_size 50m;
         	sendfile        on;
         	tcp_nopush     on;
         	keepalive_timeout 60;
         	tcp_nodelay on;
         	fastcgi_connect_timeout 300;
         	fastcgi_send_timeout 300;
         	fastcgi_read_timeout 300;
         	fastcgi_buffer_size 64k;
         	fastcgi_buffers 4 64k;
         	fastcgi_busy_buffers_size 128k;
         	fastcgi_temp_file_write_size 256k;
         	gzip on;
         	gzip_min_length  1k;
         	gzip_buffers     4 16k;
         	gzip_http_version 1.0;
         	gzip_comp_level 2;
         	gzip_types       text/plain application/x-javascript text/css application/xml;
         	gzip_vary on;
         	gzip_proxied        expired no-cache no-store private auth;
         	gzip_disable        "MSIE [1-6]\.";
         	server_tokens off;
         	log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
         		'$status $body_bytes_sent "$http_referer" '
         		'"$http_user_agent" $http_x_forwarded_for';
      
         	server {
         		listen       12345;
         		server_name  192.168.7.26;
         		root /opt/php;
         		index  index.html index.htm index.php;
         		error_page  404              /404.html;
         		location = /404.html {
         			return 404 'Sorry, File not Found!';
         		}
         		error_page  500 502 503 504  /50x.html;
         		location = /50x.html {
         			root   /usr/share/nginx/html; # windows用户替换这个目录
         		}
         		location / {
         			try_files $uri @rewrite;
         		}
         		location @rewrite {
         			set $static 0;
         			if  ($uri ~ \.(css|js|jpg|jpeg|png|gif|ico|woff|eot|svg|css\.map|min\.map)$) {
         				set $static 1;
         			}
         			if ($static = 0) {
         				rewrite ^/(.*)$ /index.php?s=/$1;
         			}
         		}
         		location ~ /Uploads/.*\.php$ {
         			deny all;
         		}
         		location ~ \.php/ {
         		   if ($request_uri ~ ^(.+\.php)(/.+?)($|\?)) { }
         		   fastcgi_pass 127.0.0.1:9000;
         		   include fastcgi_params;
         		   fastcgi_param SCRIPT_NAME     $1;
         		   fastcgi_param PATH_INFO       $2;
         		   fastcgi_param SCRIPT_FILENAME $document_root$1;
         		}
         		location ~ \.php$ {
         			fastcgi_pass 127.0.0.1:9000;
         			fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         			include fastcgi_params;
         		}
         		location ~ /\.ht {
         			deny  all;
         		}
         	}
      
         }
      
    • 启动
      vi /usr/lib/systemd/system/nginx.service

      	[Unit]
      	Description=nginx - high performance web server
      	After=network.target remote-fs.target nss-lookup.target
      	[Service]
      	Type=forking
      	ExecStart=/usr/local/nginx/sbin/nginx
      	ExecReload=/usr/local/nginx/sbin/nginx -s reload
      	ExecStop=/usr/local/nginx/sbin/nginx -s stop
      	[Install]
      	WantedBy=multi-user.target
      	
      systemctl daemon-reload //重新加载服务
      systemctl start nginx  //启动
      systemctl stop nginx  //停止
      systemctl reload nginx  //重启 可以不用停止nginx服务,使修改的配置生效
      systemctl restart nginx  //重启
      systemctl enable nginx  //设置开机启动
      systemctl disable nginx  //禁用开机启动
      systemctl status nginx  //查看服务状态
      
  3. 安装PHP(5.6)

    • 安装程序包及依赖库
      方法一:
      apt-get install python-software-properties
      apt-get install software-properties-common
      add-apt-repository ppa:ondrej/php
      apt-get update
      apt-get upgrade
      apt-get install php5.6 php5.6-fpm php5.6-mysql php5.6-gd php5.6-mbstring php5.6-curl php5.6-soap php5.6-redis php5.6-xml php5.6-apcu php5.6-mcrypt
      方法二:
      php5.6无法安装就安装php7.0

         apt-get install php7.0-fpm php7.0-mysql php7.0-common php7.0-mbstring php7.0-gd php7.0-json php7.0-cli php7.0-curl php7.0-zip libapache2-mod-php7.0
      

      vi /etc/php/7.0/fpm/pool.d/www.conf
      把listen = /run/php/php7.0-fpm.sock改为listen = 127.0.0.1:9000
      重启systemctl restart php7.0-fpm.service

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值