日子有阳光灿烂的时候 發表於 2020-3-30 00:26:00

GOLANG-配置nginx反向代理端口 配置域名

<p></p><div class="toc"><div class="toc-container-header">目录</div><ul><li>配置/etc/nginx/nginx.conf文件</li><li>新建/etc/nginx/conf.d/doc.haimait.conf文件</li><li>重启nginx服务</li><li>解析自己的域名到服务器的公网ip</li></ul></div><p></p>
<h2 id="配置etcnginxnginxconf文件">配置/etc/nginx/nginx.conf文件</h2>
<pre><code class="language-bash">#   nformation on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

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

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

events {
    worker_connections 1024;
}

http {
    log_formatmain'$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.logmain;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   300;
    types_hash_max_size 2048;
    # 配置nginx上传文件最大限制
    client_max_body_size 50m;

    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;

    server {
      listen       80 default_server;
      listen       [::]:80 default_server;
      server_name_;
       # root         /usr/share/nginx/html;

      root         /wwwroot;

      # 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 {
      }

#        location ~ .php$ {
#          root   /wwwroot;
#           fastcgi_pass 127.0.0.1:9000;
#           fastcgi_index index.php;
#          fastcgi_param SCRIPT_FILENAME /wwwroot$fastcgi_script_name;
#          fastcgi_param PHP_INFO $1;
#          includefastcgi_params;
#        }

    }
}



</code></pre>
<h2 id="新建etcnginxconfddochaimaitconf文件">新建/etc/nginx/conf.d/doc.haimait.conf文件</h2>
<p><strong>doc.haimait.conf</strong></p>
<pre><code>server {
listen 80;
server_namedoc.haimait.com;

access_log/var/log/nginx/doc.haimait.access.log;
error_log/var/log/nginx/doc.haimait.error.log;
client_max_body_size 10m;
location ~/(.well-known/pki-valtidation) {
      root /usr/share/nginx/html;
}
location / {
#   add_header Access-Control-Allow-Origin *;
#   add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
#   add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
      proxy_passhttp://127.0.0.1:8811;
      proxy_redirect   off;
      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;
      proxy_max_temp_file_size 0;
      proxy_connect_timeout      90;
      proxy_send_timeout         300;
      proxy_read_timeout         300;
      proxy_buffer_size          4k;
      proxy_buffers            4 32k;
      proxy_busy_buffers_size    64k;
      proxy_temp_file_write_size 64k;
      }
location ~ ^/lovebook/ {
#   add_header Access-Control-Allow-Origin *;
#   add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
#   add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
      proxy_passhttp://127.0.0.1:8844;
      proxy_redirect   off;
      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;
      proxy_max_temp_file_size 0;
      proxy_connect_timeout      90;
      proxy_send_timeout         300;
      proxy_read_timeout         300;
      proxy_buffer_size          4k;
      proxy_buffers            4 32k;
      proxy_busy_buffers_size    64k;
      proxy_temp_file_write_size 64k;
      }
}


server {
   #listen       443 ssl;
   #server_nametest2.haimait.com;


   #ssl_certificate /etc/letsencrypt/live/test2.haimait.com/fullchain.pem;
   #ssl_certificate_key /etc/letsencrypt/live/test2.haimait.com/privkey.pem;
   #ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
   #ssl_prefer_server_ciphers on;
   #ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

location / {
#      add_header Access-Control-Allow-Origin *;
#      add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
#      add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
      proxy_passhttp://127.0.0.1:8811;
      proxy_redirect   off;
      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;
      proxy_max_temp_file_size 0;
      proxy_connect_timeout      90;
      proxy_send_timeout         300;
      proxy_read_timeout         300;
      proxy_buffer_size          4k;
      proxy_buffers            4 32k;
      proxy_busy_buffers_size    64k;
      proxy_temp_file_write_size 64k;
    }
location ~ ^/lovebook/ {
#   add_header Access-Control-Allow-Origin *;
#   add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
#   add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
      proxy_passhttp://127.0.0.1:8844;
      proxy_redirect   off;
      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;
      proxy_max_temp_file_size 0;
      proxy_connect_timeout      90;
      proxy_send_timeout         300;
      proxy_read_timeout         300;
      proxy_buffer_size          4k;
      proxy_buffers            4 32k;
      proxy_busy_buffers_size    64k;
      proxy_temp_file_write_size 64k;
    }
}

</code></pre>
<h2 id="重启nginx服务">重启nginx服务</h2>
<pre><code class="language-bash"># pwd
/etc/nginx
# ls conf.d/
default.conf_bakdoc.haimait.confphpmyadmin.conftest.haimait.conftest.haimait.conf_bak
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# nginx -s reload

</code></pre>
<h2 id="解析自己的域名到服务器的公网ip">解析自己的域名到服务器的公网ip</h2>
<p>不会的自己百度</p>
<p>此时就已经配置成功了</p>
<p>在线地址:</p>
<p>http://doc.haimait.com/</p>


</div>
<div id="MySignature" role="contentinfo">
   
http://www.cnblogs.com/haima/<br><br>
来源:https://www.cnblogs.com/haima/p/12596118.html
頁: [1]
查看完整版本: GOLANG-配置nginx反向代理端口 配置域名