nginx

nginx下載

wget nginx1.23.1

nginx運行加載配置文件說明

nginx?會從?/etc/nginx/conf.d?中加載以?.conf?結尾的配置文件

nginx?會從?/etc/nginx/sites-enabled?中加載任何名稱的配置文件

#全局塊

影響nginx整體運行的配置指令

比如:worker_processes auto;處理并發的數量

#events塊

nginx服務器與用戶的網絡連接

比如:worker_connections 1024;支持的最大連接數

#http塊

##http全局塊

##upstream塊:負載均衡(輪詢、weight、ip_hash、fair)

##server塊:虛擬主機配置。

allow 10.10.240.24;?只允許ip10.10.240.24進行訪問。

deny? all;????拒絕所有的ip訪問,這樣設置后,就只有ip為10.10.240.24可以訪問nginx的網站。拒絕后返回的是403錯誤,這樣報403和404錯誤時直接返回維護頁面內容.


root /home/zjbj/newServer/publush_server/static/real_name;

? ? location / {

? ? ? #root? html;

? ? ? try_files $uri $uri/ @router;

? ? ? index? index.html index.htm;

? ? }

? ? location @router {

? ? ? rewrite ^.*$ /index.html last;

? ? }



openssl3.0編譯安裝

OpenSSL3.0.5安裝_七羽319的博客-CSDN博客

./config --prefix=/usr/local/openssl

yum install -y perl-CPAN

perl -MCPAN -e shell;install IPC/Cmd.pm;exit


echo '/usr/local/openssl/lib64' >>/etc/ld.so.conf

ldconfig


跨域配置

add_header 'Access-Control-Allow-Origin' *;#允許跨域請求的域,* 代表所有

add_header 'Access-Control-Allow-Headers' *;#允許請求的header

add_header 'Access-Control-Allow-Credentials' 'true';#允許帶上cookie請求

add_header 'Access-Control-Allow-Methods' *;#允許請求的方法,比如 GET,POST,PUT,DELETE


location /test {

? ? proxy_set_header Host $host;#表明請求的主機名

? ? proxy_set_header X-Real-IP $remote_addr; #當有多個代理時候,可以在第一個反向代理上配置,獲取真實客戶端IP;

????proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #轉發請求時會將上游服務器的IP地址追加到X-Forwarded-For的后面,使用英文逗號分割

? ??proxy_set_header X-Forwarded-Proto $scheme;

????proxy_pass http://192.168.107.112:8080;

}

Tomcat server.xml 的 Engine 模塊下配置一個 Valve:

<Valve className="org.apache.catalina.valves.RemoteIpValve"

remoteIpHeader="X-Forwarded-For"

protocolHeader="X-Forwarded-Proto"

protocolHeaderHttpsValue="https"/>


application.yml配置

server:

? tomcat:

? ? remote-ip-header: X-Forwarded-For

? ? protocol-header: X-Forwarded-Proto

? ? protocol-header-https-value: https


# websocket需要增加該配置

map$http_upgrade$connection_upgrade{

? ? ? default keep-alive;

? ? ? 'websocket'upgrade;

}

# 重點在這里,webSocket后面沒有斜杠,和其它項目的區別

? ? ? ? location /webSocket {

? ? ? ? ? ? proxy_pass http://abc_test_websocket_name;

? ? ? ? ? ? proxy_redirect off;

? ? ? ? ? ? proxy_set_header Host $host:5052;

? ? ? ? ? ? proxy_set_header X-Real-IP $remote_addr;

? ? ? ? ? ? proxy_set_header REMOTE-HOST $remote_addr;

? ? ? ? ? ? proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

? ? ? ? ? ? #升級http1.1到 websocket協議

? ? ? ? ? ? proxy_http_version 1.1;

? ? ? ? ? ? proxy_set_header Upgrade $http_upgrade;

? ? ? ? ? ? proxy_set_header Connection? $connection_upgrade;

? ? ? ? }

nginx中localion后路徑帶或不帶/的匹配規則


語法規則:?location [=|~|~*|^~] /uri/ { … }

=?開頭表示精確匹配

^~?開頭表示uri以某個常規字符串開頭,理解為匹配 url路徑即可。nginx不對url做編碼,因此請求為/static/20%/aa,可以被規則^~ /static/ /aa匹配到(注意是空格)。以xx開頭

~?開頭表示區分大小寫的正則匹配?以xx結尾

~*?開頭表示不區分大小寫的正則匹配?以xx結尾

!~和!~*分別為區分大小寫不匹配及不區分大小寫不匹配 的正則

/?通用匹配,任何請求都會匹配到。


docker run --name nginx -d -p 80:80 -v /home/dreamlee/nginx_conf/log:/var/log/nginx -v /home/dreamlee/nginx_conf/conf/nginx.conf:/etc/nginx/nginx.conf -v /home/dreamlee/nginx_conf/html/index.html:/usr/share/nginx/html/index.html nginx



nginx.conf配置

location / {

? ? ? ? ? ? #root? html;

? ? ? ? ? ? #index? index.html index.htm;

? ? ? ? ? ? root /opt/museum/frontend/dist;

? ? ? ? ? ? autoindex on;

? ? ? ? }


root /home/zjbj/newServer/publush_server/static/pm_jeecg;

? ? location / {

? ? ? #root? html;

? ? ? try_files $uri $uri/ @router;#需要指向下面的@router否則會出現vue的路由在nginx中刷新出現404

? ? ? index? index.html index.htm;

? ? }

? ? location @router {

? ? ? rewrite ^.*$ /index.html last;

? ? }


日志打印

log_format access-upstream '$time_iso8601|$remote_addr|[$time_local]|$protocol|$status|$bytes_sent|$bytes_received|$session_time| "$upstream_addr"|"$upstream_bytes_sent"|"$upstream_bytes_received"|"$upstream_connect_time"';

? ? map $time_iso8601 $logdate {

? ? ? ? '~^(?<ymd>\d{4}-\d{2}-\d{2})' $ymd;

? ? ? ? default 'date-not-found';

? ? }

? ? access_log logs/stream_access_$logdate.log access-upstream;


編譯安裝

./configure --prefix=/usr/local/nginx --with-stream=dynamic? ?#執行完成后,會生成很多中間文件,放在objs目錄下面

###load_module modules/ngx_stream_module.so;

make? #沒有報錯代表執行成功

make install? #安裝命令

修改nginx配置:/root/lixiang/nginx-1.23.1/auto/lib/openssl/conf?

Nginx升級加固SSL/TLS協議信息泄露漏洞(CVE-2016-2183) (bbsmax.com)

./configure --with-openssl=/usr/local/openssl-1.1.1o --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie'

./configure --with-http_ssl_module --with-openssl=/usr/local/openssl --prefix=/usr/local/nginx-1.23.1?

./configure?--with-http_ssl_module --with-openssl=/usr/local/openssl --prefix=/usr/local/nginx-1.23.1?--with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module?--http-client-body-temp-path=/usr/local/nginx-1.23.1/temp/client_temp --http-proxy-temp-path=/usr/local/nginx-1.23.1/temp/proxy_temp --http-fastcgi-temp-path=/usr/local/nginx-1.23.1/temp/fastcgi_temp --http-uwsgi-temp-path=/usr/local/nginx-1.23.1/temp/uwsgi_temp --http-scgi-temp-path=/usr/local/nginx-1.23.1/temp/scgi_temp

--add-module=nginx-module-vts


負載均衡

nginx負載均衡之一致性Hash方式_我愛吃雞翅膀的博客-CSDN博客_nginx 一致性hash

nginx 根據IP轉發到指定的后端服務器_Linux中文社區的博客-CSDN博客_nginx 根據ip轉發

Nginx之正則表達式、location匹配簡介以及rewrite重寫_mb5fd868b989ae9的技術博客_51CTO博客

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容