Nginx
十四、Nginx 虚拟主机配置例子
## HTTPS配置 ``` server { listen 80; server_name www.test.com; #域名 index index.html index.php; root /home/wwwroot/test; #项目地址 include enable-php-pathinfo.conf; rewrite ^(.*)$ https://$host$1 permanent; } server { listen 443 ssl; server_name www.test.com; #域名 root /home/wwwroot/test; #项目地址 index index.php index.html index.htm; include enable-php-pathinfo.conf; ssl_certificate /usr/local/nginx/conf/vhost/cart/test.pem; #证书 ssl_certificate_key /usr/local/nginx/conf/vhost/cart/test.key; #证书 ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location / { root /home/wwwroot/test; #项目地址 index index.php index.html index.htm; if (!-e $request_filename){ rewrite ^/(.*)$ /index.php/$1 last; } } } ``` ##http配置 ``` server { listen 80; server_name www.test.com; index index.php index.html index.htm; root /home/wwwroot/test/public; #PHP引用配置,可以注释或修改 include enable-php-pathinfo.conf; #URL重写规则引用,修改后将导致面板设置的伪静态规则失效 location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=$1 last; break; } } #禁止访问的文件或目录 location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md) { return 404; } #一键申请SSL证书验证目录相关设置 location ~ \.well-known{ allow all; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; error_log /dev/null; access_log /dev/null; } location ~ .*\.(js|css)?$ { expires 12h; error_log /dev/null; access_log /dev/null; } access_log /home/wwwlogs/test.log; error_log /home/wwwlogs/test.log; } ``` ## open_basedir open_basedir是php.ini中的一个配置选项。 它可将用户访问文件的活动范围限制在指定的区域,假设open_basedir=/home/wwwroot/home/web1/:/tmp/,那么通过web1访问服务器的,用户就无法获取服务器上除了/home/wwwroot/home/web1/和/tmp/这两个目录以外的文件。 注意用open_basedir指定的限制实际上是前缀,而不是目录名。举例来说: 若"open_basedir = /dir/user", 那么目录 "/dir/user" 和 "/dir/user1"都是可以访问的。所以如果要将访问限制在仅为指定的目录,请用斜线结束路径名。 像在一些PHP框架如thinkphp、laraval中,通常使用public作为入口目录,这时就需要设置open_basedir了,否则无法访问。 - 例子,比如一个网站的入口文件是/home/wwwroot/test/public,则在/nginx/conf/fastcgi.conf文件中添加如下内容即可 ``` fastcgi_param REDIRECT_STATUS 200; fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root:/tmp/:/proc/:/home/wwwroot/test/:/tmp/:/proc/"; ``` ================ - fastcgi.conf会被包含到enable-php-pathinfo.conf文件中: ``` location ~ [^/]\.php(/|$) { fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; include pathinfo.conf; } ``` enable-php-pathinfo.conf文件又会被包含到虚拟主机配置中,参考上面的http配置或https配置。
顶部
收展
底部
[TOC]
目录
一、 Nginx 基础知识
二、 Nginx 安装及调试
三、nginx php-fpm安装配置
四、常见错误处理
五、Nginx监控
六、Nginx 负载均衡
七、nginx反向代理配置
八、Nginx Rewrite
九、Nginx安全
十、nginx基本配置与参数说明
十一、Nginx Redirect、Location
十二、nginx 高并发配置参数
十三、Nginx 参数优化
十四、Nginx 虚拟主机配置例子
相关推荐
Apache