时间:2016-03-31 08:07 来源: 我爱IT技术网 作者:山风
部署你的NginX
当我们安装完 nginx 后除了可以拿来当网站服务器或者当成反向代理服务器使用,当还在新手时我们也总要了解 nginx 的设置档是如何配置部署的,本篇就来做个简单的了解。
主要设置档 /etc/nginx/nginx.conf
#############################################
# 这是 Nginx 服务的主要设置档
# 文件位置默认为 /etc/nginx/nginx.conf
#############################################
# 启用程序的 Linux 帐户
user nginx;
# 启用的执行绪数量(建议为你的 CPU 核心数 x 2)
worker_processes 2;
# Error Log 档的位置
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
# 允许同一时间连线总数量
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# 默认的 log 记录格式
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 档的位置
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
# 默认不会自动启动 gzip 压缩
#gzip on;
# 载入 /etc/nginx/conf.d/ 下的所有设置档
# 通常都是各个虚拟主机的配置
include /etc/nginx/conf.d/*.conf;
}其他配置档位置(虚拟主机) /etc/nginx/conf.d/*.conf
默认会自动产生两个范例设置档,其中 default.conf 为一般虚拟主机设置档,example_ssl.conf 为 SSL 的虚拟主机设置档。
默认主机的配置 /etc/nginx/conf.d/default.conf
server {
# 这个虚拟主机的 Port 和名称
listen 80;
server_name localhost;
# 默认编码,但通常不建议开启,让网页中的 meta 或 header 自行定义
#charset koi8-r;
# 可以额外针对这个站台修改 log 的存放位置
#access_log /var/log/nginx/log/host.access.log main;
# 根目录的设置
location / {
# 实际的文件位置
root /usr/share/nginx/html;
# 默认首页文件名
index index.html index.htm;
}
# 如果发生 404 可以指定到特定的页面来显示
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
