nginx 虚拟主机配置
user nginx; #代表使用的用户
worker_processes auto; #工作衍生进程数,一般代表系统cpu核数一到两倍最好
error_log /var/log/nginx/error.log; #错误日至文件
pid /run/nginx.pid; #设置pid存放路径,pid是控制系统中的一个重要的控制文件 # Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf; #设置最大链接数
events {
worker_connections 1024;
} #网页相关配置
http {
#gzip on;开启gizp压缩,设置用户访问时,是否开启压缩功能,提高文件数据传输速度
#chatset gb2312;设置字符编码
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048; include /etc/nginx/mime.types;
default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf; server {
listen 80 default_server;#nginx默认访问端口
server_name _;
#root /usr/share/nginx/html;
index index.html index.php;
root /var/www/html; # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf; location / {
}
配置php
location ~ \.php { #这里php 后面本来有个$ 为了支持thinkphp url模式 而去了
fastcgi_pass 127.0.0.1:9000;#php-fpm的默认端口是9000
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(.*)$; #支持thinkphp url 模式
fastcgi_param PATH_INFO $fastcgi_path_info; #支持thinkphp url 模式
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
listen 80; #需要监听的端口
server_name xxx.xxx; #域名
index index.html index.php; #默认访问文件
root /var/www/xxx; #虚拟主机目录
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
gzip on;#开启gizp压缩,设置用户访问时,是否开启压缩功能,提高文件数据传输速度
gzip_min_length 1k;#需要压缩的文件最小1k
gzip_buffers 16k;#申请内存大小来存储压缩的文件,4个16k的数据流
gzip_http_version 1.1;#gzip技术支持的http版本1.
#以上为最常用的配置
gzip_vary on;#首先判断客户端是否支持gzip压缩技术,不支持的不就不进行gzip技术压缩
pathInfo
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$ last;
}
开启目录访问在对应的sever的location 中添加autoindex on;即可;
编译安装:
下载nginx=>wget http://nginx.org/download/nginx-1.10.2.tar.gz
解压tar -zxvf nginx
编译:./configure --prefix=/etc/nginx安装路径 (如果缺少什么模块或者组建,安装缺少的。需要pcre 先看看系统中有没有安装pcre和pcre-devel,没有就使用yum 安装)
make && make install
完成!
错误:403
最有可能是项目目录没有权限 chmod 755 xxx
开启php 错误提示:1:修改/etc/php.ini 中 display_errors = On;修改/etc/php-fpm.d/www.conf中display_errors = on;重启nginx和php-fpm
nginx 虚拟主机配置的更多相关文章
- nginx虚拟主机配置
nginx虚拟主机配置 虚拟主机的概念虚拟主机,就是把一台物理服务器划分成多个"虚拟"的服务器,每一个虚拟主机都可以有独立的域名和独立的目录nginx虚拟主机的配置nginx的 ...
- Nginx高性能服务器安装、配置、运维 (5) —— Nginx虚拟主机配置
六.Nginx虚拟主机配置 建立基于域名的虚拟主机: (1)建立基于域名的虚拟主机配置文件(以abc.com为例): (2)更改虚拟主机配置文件: 更改配置如下(更改部分即可): server { l ...
- Nginx教程(二) Nginx虚拟主机配置
Nginx教程(二) Nginx虚拟主机配置 1 虚拟主机管理 1.1 Nginx管理虚拟主机 虚拟主机使用的是特殊的软硬件技术,它把一台运行在因特网上的服务器主机分成一台台“虚拟”的主机,每台虚拟主 ...
- Nginx网络架构实战学习笔记(一):Nginx简介、安装、信号控制、nginx虚拟主机配置、日志管理、location 语法、Rewrite语法详解
文章目录 nginx简介 nginx安装 nginx信号控制 nginx虚拟主机配置 日志管理 location 语法 精准匹配的一般匹配 正则匹配 总结 Rewrite语法详解 nginx简介 Ng ...
- Nginx教程(二) Nginx虚拟主机配置 (转)
Nginx教程(二) Nginx虚拟主机配置 1 虚拟主机管理 1.1 Nginx管理虚拟主机 虚拟主机使用的是特殊的软硬件技术,它把一台运行在因特网上的服务器主机分成一台台“虚拟”的主机,每台虚拟主 ...
- Nginx虚拟主机配置(20200202)
一台机器上跑多个站点,即多个域名 curl -xIP:port 域名 用来指定访问的域名在哪个IP的哪个端口上 Nginx默认虚拟主机 不管什么域名解析到该服务器,都会访问到默认虚拟主机 ngi ...
- Nginx虚拟主机配置教程
说明:配置之前先把域名解析到服务器IP地址上 站点1:bbs.osyunwei.com 程序所在目录/data/osyunwei/bbs 站点2:sns.osyunwei.com 程序所在目录/d ...
- nginx虚拟主机配置实践
1.配置基于域名的虚拟主机 [root@web01 html]# egrep -v "#|^$" /application/nginx/conf/nginx.conf.defaul ...
- Nginx虚拟主机配置--配置Nginx的主配置文件
单台Nginx WEB服务器同时会配置N个网站,也可称之为配置N个虚拟域名的主机,即多个域名对应同一个80端 口. 每个虚拟主机可以是一个独立网站.可以具有独立域名,同一台物理机上面的虚拟主机相互之间 ...
随机推荐
- 透过HT for Web 3D看动画Easing函数本质
http://www.hightopo.com/guide/guide/plugin/form/examples/example_easing.html 50年前的这个月诞生了BASIC这门计算机语言 ...
- PreEmptive Dotfuscator and Analytics CE
PreEmptive Dotfuscator and Analytics CE Dotfuscator 是领先的 .NET 模糊处理程序和压缩程序,有助于防止程序遭到反向工程,同时使程序更小更高效.D ...
- js数组去重
这就是数组去重了...var str=['hello','node','element','node','hello','blue','red'];var str1=[]; function firs ...
- EF6.0 Code First使用mysql的各种错误和解决办法!!
1.修改或者添加connectionStrings <connectionStrings> <add name="MvcDBContext" connection ...
- css图片精灵
<ul> <li class="top"> <em>01</em> <p><a href="http:/ ...
- Maven创建web项目:SpringMVC+Mybatis 【转】
IDEA14创建Maven管理的SpringMVC+Mybatis,web项目 项目构建步骤 1.File->New->Project 勾选Create from archetype 点击 ...
- swift 如何在IOS应用图标上添加消息数
在应用图标右上角添加消息数提醒,可以很方便的告知用户该应用中有无新消息需要处理.下面用xcode 7.3.1来简要说明一下如何用swift语言进行此功能的实现. 1.修改 AppDelegate.sw ...
- 节日来了发个HTML5红包
效果图: 请关注微信公众号 何问起 , 账号ihewenqi ,或者微信扫描下图二维码: 关注后发送 愚人节 ,或 微信节日红包 ,可以体验效果. 代码如下: <!DOCTYPE html> ...
- [deviceone开发]-动态添加组件add方法的示例
一.简介 这个示例详细介绍ALayout的add方法的使用(原理也适用于Linearlayout),以及add上去的新ui和已有的ui如何数据交换,初学者推荐.二.效果图 三.相关下载 https:/ ...
- simplestyle
simplestyle-spec A simple specification for styling GeoJSON data. Versions 1.1.0 Adds properties to ...