nginx安装及常用配置

1. 安装

yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
yum install nginx


操作指令:
  systemctl start nginx.service

  systemctl stop nginx.service

  systemctl restart nginx.service

 

 2. 配置文件:配置文件: /etc/nginx/nginx.conf

3. 配置示例

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 2048;
}

http {
    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;
    tcp_nodelay         on;
    keepalive_timeout   3600;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    upstream ceds_server {
         server 127.0.0.1:8001;
     }
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
     # 前端项目部署
        location / {
      # URI 重定向     try_files $uri $uri/ /index.html;     # index  index.html index.html; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } server {
      # 后端监听端口 及 域名 listen 8080; server_name 10.13.192.225; location / {
# uwsgi协议, proxy uwsgi超时时间,文件及body上传参数大小 include uwsgi_params; uwsgi_pass ceds_server;    uwsgi_connect_timeout 3600;    uwsgi_read_timeout 3600;    uwsgi_send_timeout 3600;    client_max_body_size 1000M; client_body_buffer_size 1000M; proxy_read_timeout 3600; proxy_connect_timeout 3600; proxy_send_timeout 3600; } } # Settings for a TLS enabled server. # # server { # listen 443 ssl http2 default_server; # listen [::]:443 ssl http2 default_server; # server_name _; # root /usr/share/nginx/html; # # ssl_certificate "/etc/pki/nginx/server.crt"; # ssl_certificate_key "/etc/pki/nginx/private/server.key"; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 10m; # ssl_ciphers PROFILE=SYSTEM; # ssl_prefer_server_ciphers on; # # # Load configuration files for the default server block. # include /etc/nginx/default.d/*.conf; # # location / { # } # # error_page 404 /404.html; # location = /40x.html { # } # # error_page 500 502 503 504 /50x.html; # location = /50x.html { # } # } }

4. server http https

# http
upstream message { server localhost:8080 max_fails=3; } server { listen 80; server_name localhost; location / { root html; index index.html index.htm; #允许cros跨域访问 add_header 'Access-Control-Allow-Origin' '*'; #proxy_redirect default; #跟代理服务器连接的超时时间,必须留意这个time out时间不能超过75秒,当一台服务器当掉时,过10秒转发到另外一台服务器。 proxy_connect_timeout 10; } location /message { proxy_pass http://message; proxy_set_header Host $host:$server_port; } }

# https
upstream message {
server localhost:8080 max_fails=3;
}

server {
listen 443 ssl;
server_name localhost;
ssl_certificate /usr/local/nginx-1.17.8/conf/keys/binghe.pem;
ssl_certificate_key /usr/local/nginx-1.17.8/conf/keys/binghe.key;
ssl_session_timeout 20m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_verify_client off;
location / {
root html;
index index.html index.htm;
#允许cros跨域访问
add_header 'Access-Control-Allow-Origin' '*';
#跟代理服务器连接的超时时间,必须留意这个time out时间不能超过75秒,当一台服务器当掉时,过10秒转发到另外一台服务器。
proxy_connect_timeout 10;
}

location /message {
proxy_pass http://message;
proxy_set_header Host $host:$server_port;
}
}
http,https 原文地址: https://www.cnblogs.com/binghe001/p/14752404.html
 

 

posted @ 2023-03-03 15:57  韩增  阅读(48)  评论(0)    收藏  举报