nginx 配置文件


#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
worker_connections 1024;
}


http {
include mime.types;
default_type application/octet-stream;

#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 logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

# 负载均衡
#upstream xtqg0304{
# ip_hash;
# hash $request_uri;
# server 127.0.0.1:8001 down;
# server 127.0.0.1:8002 backup;
# server 127.0.0.1:8003 max_fails=1 fail_timeout=10s;
#}

#proxy_cache_path /xtag0304/cache levels=1:2 keys_zone=xtqg0304_cache:10m max_size=10g inactive=60m use_temp_path=off;

server {
listen 80;
server_name localhost;

#charset koi8-r;
#sendfile on; gzip 时开启
#access_log logs/host.access.log main;
#location /mystatus {
# stub_status;
#}

location / {
#expires 24h; 缓存设置相关
#add_header Access-Control-Allow-Origin *; 允许所有的跨域访问
#add_header Access-Control-Allow-Origin http://www.baidu.com; 允许跨域访问的地址
#add_header Access-Control-Allow-Method GET,POST,PUT,DELETE,OPTIONS; 允许跨域访问的方法
root html;
#random_index on; 随机主页面
#allow 10.18.72.34/70; 允许的ip访问
#deny all; 其他所有ip都不能访问
#deny 10.18.72.34; 不允许的ip访问
#allow all; 允许所有IP访问
#auth_basic "Auth access test! input your passward";
#auth_basic_user_file conf/htpasswd;
index index.html index.htm;
#sub_filter 'nginx' 'NGINX'; 过滤固定的字符串
#sub_filter_once off; 全部替换

}
#if($request_uri ~ ^/(login|register|password\/reset)){
# set $cookie_nocache 1;
#}
#location ~ ^/vehicel {
# rewrite ^/vehicel /test/ last; 实现url 重定向
# rewrite ^/vehicel /test/ break; 实现url 重定向
#}
#反向代理
#location ~ /test_proxy.html$ {
# proxy_cache xtqg0304_cache;
# proxy_pass http://127.0.0.1:8080;
# proxy_cache_valid 200 304 12h; 请求状态为200 304 缓存12小时
# proxy_cache_valid any 10m; 请求状态 存10分钟
# proxy_cache_key $host$uri$is_args$args; 缓存key 的重新定义
# proxy_no_cache $cookie_nocache $arg_nocache $arg_comments; 设置不缓存的url地址
# add_header Nginx-Cache "$upstream_cache_status"; 客户端头信息
# proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; 跳过本台负载的服务器
# proxy_redirect default;

# proxy_set_header Host $http_host;
# proxy_set_header X-Real-IP $remote_addr;

# proxy_connect_timeout 300;
# proxy_send_timeout 600;
# proxy_read_timeout 600;

# proxy_buffer_size 32k;
# proxy_buffering on;
# proxy_buffers 4 128k;
# proxy_busy_buffers_size 256k;
# proxy_max_temp_file_size 256k;
#}

#正向代理(需要将IP添加到浏览器的代理中HTTP中)
#resolver 8.8.8.8;
#location / {
# proxy_pass http://$http_host$request_uri;
#}


#压缩图片
#location ~ .*\.(jpg|gif|png)$ {
# gzip on;
# gzip_http_version 1.1;
# gzip_comp_level 2;
# gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
# valid_referers none blocked 10.18.72.34 ~/google\./; 防盗链(防止盗用资源) 防止一些网站访问资源
# if($invalid_referer){
# return 403;
# }
# root html/images;
#}

#压缩txt和xml
#location ~ .*\.(txt|xml)$ {
# gzip on;
# gzip_http_version 1.1;
# gzip_comp_level 2;
# gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
# root html/doc;
#}

#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 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;
#}
}

server {
listen 8080;
listen localhost:8080;
server_name localhost:8080;

location / {
root html/test8080;
index index.html index.htm;
}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}


# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}
posted @ 2018-10-17 17:36  小淘气鬼--弟弟  阅读(144)  评论(0编辑  收藏  举报