PHP小丑 发表于 2022-7-23 10:02:15

Linux安装Nginx并配置启动命令

#usernobody;worker_processes1;
#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
#pid      logs/nginx.pid;
events {
worker_connections65535;
}
http {
include       mime.types;
default_typeapplication/octet-stream;
#log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
#                  '$status $body_bytes_sent "$http_referer" '
#                  '"$http_user_agent" "$http_x_forwarded_for"';
#access_loglogs/access.logmain;
sendfile      on;
#tcp_nopush   on;
#keepalive_timeout0;
keepalive_timeout65;
gzip    on;
#允许压缩的最小字节数
gzip_min_length 1k;
#4个单位为16k的内存作为压缩结果流缓存
gzip_buffers 4 16k;
#设置识别HTTP协议版本,默认是1.1
gzip_http_version 1.1;
#gzip压缩比,可在1~9中设置,1压缩比最小,速度最快,9压缩比最大,速度最慢,消耗CPU
gzip_comp_level 2;
#压缩的类型
gzip_types text/plain application/x-javascript text/css application/xml;
#让前端的缓存服务器混村经过的gzip压缩的页面
gzip_vary   on;
# 配置转发到8700 端口
upstreamhuida{
server127.0.0.1:8700;
}
server {
listen       80;
listen       443 ssl;   # 配置https,监听433端口
server_namexxx.xxx;                  # 注意如果申请了域名配置再此,如果配置了证书才能https访问
error_page 405 =200 $request_uri;
ssl_certificatecert/7629385.pem;
ssl_certificate_key cert/7629385.key;
client_max_body_size 50m;
underscores_in_headers on;
proxy_set_header Host      $host;
proxy_set_headerX-Real-IP      $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
index index.htm index.html index.php;
proxy_connect_timeout 60; #建立tcp协议的连接时间
proxy_send_timeout 60;    #发送接口的时间
proxy_read_timeout 60;    #读取时间(接口响应时间)
#charset koi8-r;
#access_loglogs/host.access.logmain;
# 配置转发
location /huida/ {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Token';
add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Token';
proxy_pass
}
location / {
root   /home/html/huida/;
indexindex.html index.htm;
}
#静态文件交给nginx处理 代理前端静态资源
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
{
root /home/html/huida/;
expires 12;
}
#静态文件交给nginx处理
location ~ .*\.(js|css)?$
{
root /home/html/huida/;
expires 15d;
}
#error_page404            /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
#}
# 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_indexindex.php;
#    fastcgi_paramSCRIPT_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 {
#    denyall;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_namesomenamealiasanother.alias;
#    location / {
#      root   html;
#      indexindex.html index.htm;
#    }
#}
# HTTPS server
#
#server {
#    listen       443 ssl;
#    server_namelocalhost;
#    ssl_certificate      cert.pem;
#    ssl_certificate_keycert.key;
#    ssl_session_cache    shared:SSL:1m;
#    ssl_session_timeout5m;
#    ssl_ciphersHIGH:!aNULL:!MD5;
#    ssl_prefer_server_cipherson;
#    location / {
#      root   html;
#      indexindex.html index.htm;
#    }
#}
}

http://blog.itpub.net/70003733/viewspace-2906811/
页: [1]
查看完整版本: Linux安装Nginx并配置启动命令