视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
Linux环境下安装Nginx及其使用方法
2020-11-27 20:01:20 责编:小采
文档

五、CentOS7.0+ nginx实现停止、启动、重启

systemctl stop nginx.service 
systemctl start nginx.service
systemctl restart nginx.service
systemctl status nginx.service

开机自启:

systemctl enable nginx.service

取消开机自启:

systemctl disable nginx.service

六、nginx.conf配置示例

我的配置:

user nginx;
worker_processes 4;

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_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;

 keepalive_timeout 65;

 #gzip on;

 include /etc/nginx/conf.d/*.conf;

 #设定负载均衡的服务器列表
 upstream pay_server {
 ip_hash;
 server 10.74.248.01:8088 max_fails=2 fail_timeout=2;
 server 10.74.248.02:8088 max_fails=2 fail_timeout=2;
 }

 upstream print_server {
 ip_hash;
 server 10.74.248.03:2001 max_fails=2 fail_timeout=2;
 server 10.74.248.04:2001 max_fails=2 fail_timeout=2;
 }

 upstream accss_door_server {
 ip_hash;
 server 10.74.248.05:2002 max_fails=2 fail_timeout=2;
 server 10.74.248.06:2002 max_fails=2 fail_timeout=2;
 }
 
 server {
 listen 80;
 server_name wab.kupu.ccoop.com.cn;
 location /invengo {
 proxy_pass http://pay_server;
 index index.jsp index.html index.htm;
 }
 location /invengo/epc {
 proxy_pass http://print_server;
 index index.jsp index.html index.htm;
 }
 location /invengo/print {
 proxy_pass http://print_server;
 index index.jsp index.html index.htm;
 }

 location /checkout {
 proxy_pass http://accss_door_server;
 index index.jsp index.html index.htm;
 }
 location /asset {
 proxy_pass http://accss_door_server;
 index index.jsp index.html index.htm;
 }
 }

常用的nginx.conf配置:

user www www;
worker_processes 2;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
 use epoll;
 worker_connections 2048;
}
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 65;
 # gzip压缩功能设置
 gzip on;
 gzip_min_length 1k;
 gzip_buffers 4 16k;
 gzip_http_version 1.0;
 gzip_comp_level 6;
 gzip_types text/html text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
 gzip_vary on;
 
 # http_proxy 设置
 client_max_body_size 10m;
 client_body_buffer_size 128k;
 proxy_connect_timeout 75;
 proxy_send_timeout 75;
 proxy_read_timeout 75;
 proxy_buffer_size 4k;
 proxy_buffers 4 32k;
 proxy_busy_buffers_size k;
 proxy_temp_file_write_size k;
 proxy_temp_path /usr/local/nginx/proxy_temp 1 2;
 # 设定负载均衡后台服务器列表 
 upstream backend { 
 #ip_hash; 
 server 192.168.10.100:8080 max_fails=2 fail_timeout=30s ; 
 server 192.168.10.101:8080 max_fails=2 fail_timeout=30s ; 
 }
 # 很重要的虚拟主机配置
 server {
 listen 80;
 server_name itoatest.example.com;
 root /apps/oaapp;
 charset utf-8;
 access_log logs/host.access.log main;
 #对 / 所有做负载均衡+反向代理
 location / {
 root /apps/oaapp;
 index index.jsp index.html index.htm;
 proxy_pass http://backend; 
 proxy_redirect off;
 # 后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
 proxy_set_header Host $host;
 proxy_set_header X-Real-IP $remote_addr; 
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
 
 }
 #静态文件,nginx自己处理,不去backend请求tomcat
 location ~* /download/ { 
 root /apps/oa/fs; 
 
 }
 location ~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ 
 { 
 root /apps/oaapp; 
 expires 7d; 
 }
 location /nginx_status {
 stub_status on;
 access_log off;
 allow 192.168.10.0/24;
 deny all;
 }
 location ~ ^/(WEB-INF)/ { 
 deny all; 
 }
 #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;
 }
 }
 ## 其它虚拟主机,server 指令开始
}

下载本文
显示全文
专题