首页 Linux nginx 配置管理 – 简单也复杂

nginx 配置管理 – 简单也复杂

由于涉及到h5与后端交互,跨域问题,所以公司的开放测试服务器让我们自己搞nginx。顺便提升一下nginx的实践。nginx的安装,没什么难度了,百度一堆,如果源码安装就一步步来吧。(最简单的方式:yum install nginx (centos), apt-get install nginx(ubuntu))

  由于涉及到h5与后端交互,跨域问题,所以公司的开放测试服务器让我们自己搞nginx。顺便提升一下nginx的实践。

nginx的安装,没什么难度了,百度一堆,如果源码安装就一步步来吧。(最简单的方式:yum install nginx (centos),apt-get install nginx(ubuntu)) nginx.conf,作为最外层的配置文件,主要设置一些基础的配置就好了,如内存配置,日志格式配置,线程配置等,最后使用一个include conf.d/* 将其他配置文件包含进来即可。

【nginx.conf 基础配置】

error_log /data/var/log/nginx/<span style=”color: #000000″>error.log debug;

error_log logs/<span style=”color: #000000″>error.log notice;

error_log logs/error.log <span style=”color: #0000ff”>info<span style=”color: #000000″>;

pid logs/<span style=”color: #000000″>nginx.pid;

events {
worker_connections <span style=”color: #800080″>1024<span style=”color: #000000″>;
}

load modules compiled as Dynamic Shared Object (DSO)

dso {

load ngx_http_fastcgi_module.so;

load ngx_http_rewrite_module.so;

}

http {
include mime.types;
default_type application/octet-<span style=”color: #000000″>stream;
autoindex off;
server_tokens off;

server_names_hash_bucket_size </span><span style="color: #800080"&gt;128</span><span style="color: #000000"&gt;;
client_header_buffer_size 32k;
large_client_header_buffers </span><span style="color: #800080"&gt;4</span><span style="color: #000000"&gt; 32k;
client_max_body_size 20m;
client_body_buffer_size 256k;

sendfile on;
tcp_nopush     on;
keepalive_timeout </span><span style="color: #800080"&gt;60</span><span style="color: #000000"&gt;;
tcp_nodelay on;

fastcgi_connect_timeout </span><span style="color: #800080"&gt;300</span><span style="color: #000000"&gt;;
fastcgi_send_timeout </span><span style="color: #800080"&gt;300</span><span style="color: #000000"&gt;;
fastcgi_read_timeout </span><span style="color: #800080"&gt;300</span><span style="color: #000000"&gt;;
fastcgi_buffer_size 128k;
fastcgi_buffers </span><span style="color: #800080"&gt;32</span><span style="color: #000000"&gt; 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;

</span><span style="color: #0000ff"&gt;gzip</span><span style="color: #000000"&gt;  on;
gzip_disable </span><span style="color: #800000"&gt;"</span><span style="color: #800000"&gt;msie6</span><span style="color: #800000"&gt;"</span><span style="color: #000000"&gt;;
gzip_vary on;
gzip_comp_level </span><span style="color: #800080"&gt;2</span><span style="color: #000000"&gt;;
gzip_min_length 1k;
gzip_buffers </span><span style="color: #800080"&gt;4</span><span style="color: #000000"&gt; 16k;
gzip_http_version </span><span style="color: #800080"&gt;1.1</span><span style="color: #000000"&gt;;
gzip_types text</span>/plain application/x-javascript text/css application/xml application/<span style="color: #000000"&gt;javascript;

log_format main </span><span style="color: #800000"&gt;'</span><span style="color: #800000"&gt;$request_time $upstream_response_time $remote_addr - $upstream_addr [$time_local] </span><span style="color: #800000"&gt;'</span>
<span style="color: #800000"&gt;'</span><span style="color: #800000"&gt;"$host" "$request" $status $bytes_sent </span><span style="color: #800000"&gt;'</span>
<span style="color: #800000"&gt;'</span><span style="color: #800000"&gt;"$http_referer" "$http_user_agent" "$gzip_ratio" "$http_x_forwarded_for" - "$server_addr" </span><span style="color: #800000"&gt;'</span><span style="color: #000000"&gt;;

access_log </span>/data/var/log/nginx/<span style="color: #000000"&gt;access.log main;

include conf.d</span><span style="color: #008000"&gt;/*</span><span style="color: #008000"&gt;.conf;

}

【conf.d/*,具体的域名配置,http://】

.:.:.:.:server {
listen <span style=”color: #800080″>80<span style=”color: #000000″>;
server_name 3ctest.x123.com;
location /<span style=”color: #000000″> {
proxy_pass http:<span style=”color: #008000″>//<span style=”color: #008000″>3ctest_x123_com;
<span style=”color: #000000″> proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-<span style=”color: #000000″>IP $remote_addr;
proxy_set_header X-Forwarded-<span style=”color: #000000″>For $proxy_add_x_forwarded_for;
proxy_connect_timeout <span style=”color: #800080″>60<span style=”color: #000000″>;
proxy_read_timeout <span style=”color: #800080″>600<span style=”color: #000000″>;
proxy_send_timeout <span style=”color: #800080″>600<span style=”color: #000000″>;
}
}

server {
listen <span style=”color: #800080″>80<span style=”color: #000000″>;
server_name mytest.x123.com;
location /<span style=”color: #000000″> {
proxy_pass http:<span style=”color: #008000″>//<span style=”color: #008000″>mytest_x123_com;
<span style=”color: #000000″> proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-<span style=”color: #000000″>IP $remote_addr;
proxy_set_header X-Forwarded-<span style=”color: #000000″>For $proxy_add_x_forwarded_for;
proxy_connect_timeout <span style=”color: #800080″>60<span style=”color: #000000″>;
proxy_read_timeout <span style=”color: #800080″>600<span style=”color: #000000″>;
proxy_send_timeout <span style=”color: #800080″>600<span style=”color: #000000″>;
}
}

server {
listen <span style=”color: #800080″>80<span style=”color: #000000″>;
server_name 3capi.x123.com;
location /<span style=”color: #000000″> {
proxy_pass http:<span style=”color: #008000″>//<span style=”color: #008000″>3capi_x123_com;
<span style=”color: #000000″> proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-<span style=”color: #000000″>IP $remote_addr;
proxy_set_header X-Forwarded-<span style=”color: #000000″>For $proxy_add_x_forwarded_for;
proxy_connect_timeout <span style=”color: #800080″>60<span style=”color: #000000″>;
proxy_read_timeout <span style=”color: #800080″>600<span style=”color: #000000″>;
proxy_send_timeout <span style=”color: #800080″>600<span style=”color: #000000″>;
}
}

server {
listen <span style=”color: #800080″>80<span style=”color: #000000″>;
server_name yhapi.x123.com;
location /<span style=”color: #000000″> {
proxy_pass http:<span style=”color: #008000″>//<span style=”color: #008000″>yhapi_x123_com;
<span style=”color: #000000″> proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-<span style=”color: #000000″>IP $remote_addr;
proxy_set_header X-Forwarded-<span style=”color: #000000″>For $proxy_add_x_forwarded_for;
proxy_connect_timeout <span style=”color: #800080″>60<span style=”color: #000000″>;
proxy_read_timeout <span style=”color: #800080″>600<span style=”color: #000000″>;
proxy_send_timeout <span style=”color: #800080″>600<span style=”color: #000000″>;
}
}

server {
listen <span style=”color: #800080″>80<span style=”color: #000000″>;
server_name <span style=”color: #800080″>192.168.<span style=”color: #800080″>1.22<span style=”color: #000000″>;
location /<span style=”color: #000000″> {
proxy_pass http:<span style=”color: #008000″>//<span style=”color: #008000″>192.168.1.22;
<span style=”color: #000000″> proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-<span style=”color: #000000″>IP $remote_addr;
proxy_set_header X-Forwarded-<span style=”color: #000000″>For $proxy_add_x_forwarded_for;
proxy_connect_timeout <span style=”color: #800080″>60<span style=”color: #000000″>;
proxy_read_timeout <span style=”color: #800080″>600<span style=”color: #000000″>;
proxy_send_timeout <span style=”color: #800080″>600<span style=”color: #000000″>;
}
}

本文来自网络,不代表云浮站长网立场。转载请注明出处: https://www.0766zz.com/html/zhonghe/fwq/linux/20200916/10313.html
上一篇
下一篇

作者: dawei

【声明】:云浮站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

为您推荐

返回顶部