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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# http<br>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;
    }
}<br><br># httpsupstream message {<br>  server localhost:8080 max_fails=3;<br>}<br><br>server {<br>   listen       443 ssl;<br>   server_name localhost;<br>   ssl_certificate    /usr/local/nginx-1.17.8/conf/keys/binghe.pem;<br>   ssl_certificate_key /usr/local/nginx-1.17.8/conf/keys/binghe.key;<br>   ssl_session_timeout 20m;<br>   ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;<br>   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;<br>   ssl_prefer_server_ciphers on;<br>   ssl_verify_client off;<br>   location / {<br>      root   html;<br>      index  index.html index.htm;<br>      #允许cros跨域访问<br>      add_header 'Access-Control-Allow-Origin' '*';<br>      #跟代理服务器连接的超时时间,必须留意这个time out时间不能超过75秒,当一台服务器当掉时,过10秒转发到另外一台服务器。<br>      proxy_connect_timeout 10;<br>   }<br><br>    location /message {<br>      proxy_pass                  http://message;<br>      proxy_set_header Host $host:$server_port;<br>   }<br>}http,https 原文地址: https://www.cnblogs.com/binghe001/p/14752404.html
 

 

posted @   韩增  阅读(35)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类
点击右上角即可分享
微信分享提示