进入配置文件:
Nginx配置文件分为三大块:全局块,events块,http块
全局块:
events块
#===================全局块开始====================== #user nobody; #工作进程数,一般配置成和cpu数量一致 worker_processes 1; #全局错误日志及pid文件存放位置 error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #nginx 启动master进程pid号 #pid logs/nginx.pid; #=================全局块结束============================ #==============events块开始====================== events {
#标识单个worker进程的最大并发数 worker_connections 1024; } #============events块结束============================ #============http块开始(nginx服务器中配置最频繁的部分,配置虚拟主机,监听端口,请求转发等等)========================== http {
#引入 mime 类型定义文件 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压缩 #gzip on; #此处配置多台tomcat服务器(名称不能有下划线:webServer) upstream webServer{
server 127.0.0.1:8081; server 127.0.0.1:8082; } #此处配置多台tomcat服务器(名称不能有下划线:webs2Server) #upstream webs2Server{
#server 192.168.30.19:8083; #server 192.168.32.12:8085; #} server {
#定义当前这个server监听的端口 listen 80; #定义使用localhost访问 server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #默认请求地址,如果请求是:192.168.10.80:80/ 那么会进入这个里面的tomcat反向代理地址 #一个location里面只能有一个proxy_pass location / {
#此处可以配置Tomcat反向代理地址比如: #此处可以引用上面upstream 的多台tomcat;也可以单独配置一台 proxy_pass http://127.0.0.1:8081/; #配置单台 #proxy_pass http://webServer/; #引用上面的多台
#引用上面的多台配置
# root html; #默认的网站根目录的位置 #index index.html index.htm; #网站的欢迎页,起始页 } #表示如果请求是:192.168.10.80:80/web 那么会进入这个里面的tomcat反向代理地址 location /web {
#此处引用上面的配置的多台tomcat #proxy_pass http://127.0.0.1:8082/; #proxy_pass http://web2Server/; #引用上面的多台Tomcat配置 } #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; #} } # 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; # } #} }
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/208581.html原文链接:https://javaforall.net
