日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > centos >内容正文

centos

Centos7编译安装nginx并设置反向代理

發(fā)布時間:2025/3/19 centos 72 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Centos7编译安装nginx并设置反向代理 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一、編譯部署Nginx 1.12

安裝配置:

[root@localhost?~]#?groupadd?nginx [root@localhost?~]#?useradd?-s?/sbin/nologin?-g?nginx?-M?nginx [root@localhost?~]#?systemctl?stop?firewalld [root@localhost?~]#?systemctl?disable?firewalld #關掉selinux #服務器文件描述符等

[root@localhost?~]#?yum?install?gcc?gcc-c++?glibc?automake?pcre?zlip?zlib-devel?openssl-devel?pcre-devel?wget?lrzsz [root@localhost?~]#?cd?/usr/local/src/ [root@localhost?src]#?wget?http://nginx.org/download/nginx-1.12.0.tar.gz [root@localhost?src]#?tar?-zxvf?nginx-1.12.0.tar.gz [root@localhost?src]#?cd?nginx-1.12.0 [root@localhost?nginx-1.12.0]#?./configure?--prefix=/usr/local/nginx?--user=nginx?--group=nginx?--with-http_ssl_module?--with-http_flv_module?--with-http_stub_status_module?--with-http_gzip_static_module??--with-pcre [root@localhost?nginx-1.12.0]#?make [root@localhost?nginx-1.12.0]#?make?install

備注:

--prefix:Nginx安裝目錄
--user:Nginx用戶
--group:Nginx用戶所屬組
--with-http_ssl_module:提供https支持
--with-http_flv_module:搭建flv視頻服務器使用的
--with-http_stub_status_module:開啟Stub Status模塊,該模塊會產(chǎn)生一個服務器狀態(tài)和信息頁
--with-http_gzip_static_module:開啟Gzip靜態(tài)模塊,該模塊用于發(fā)送預壓縮文件
--with-pcre:perl執(zhí)行文件路徑


配置服務:

[root@localhost?nginx-1.12.0]#?vi?/usr/lib/systemd/system/nginx.service [Unit] Description=The?nginx?HTTP?and?reverse?proxy?server After=network.target?remote-fs.target?nss-lookup.target [Service] Type=forking?? PIDFile=/usr/local/nginx/logs/nginx.pid?? ExecStartPre=/usr/bin/rm?-f?/run/nginx.pid?? ExecStartPre=/usr/local/nginx/sbin/nginx?-t?? ExecStart=/usr/local/nginx/sbin/nginx?? ExecReload=/bin/kill?-s?HUP?$MAINPID?? KillMode=process?? KillSignal=SIGQUIT?? TimeoutStopSec=5?? PrivateTmp=true [Install] WantedBy=multi-user.target


驗證:

[root@localhost?nginx-1.12.0]#?chmod?a+x?/usr/lib/systemd/system/nginx.service [root@localhost?nginx-1.12.0]#?/usr/local/nginx/sbin/nginx?-t nginx:?the?configuration?file?/usr/local/nginx/conf/nginx.conf?syntax?is?ok nginx:?configuration?file?/usr/local/nginx/conf/nginx.conf?test?is?successful [root@localhost?nginx-1.12.0]#?systemctl?start?nginx [root@localhost?nginx-1.12.0]#?ps?-ef?|?grep?nginx root??????24412??????1??0?16:31??????????00:00:00?nginx:?master?process?/usr/local/nginx/sbin/nginx nginx?????24413??24412??0?16:31??????????00:00:00?nginx:?worker?process root??????24415??10541??0?16:31?pts/0????00:00:00?grep?--color=auto?nginx


訪問:

http://192.168.146.136




二、nginx配置反向代理

設置nginx配置文件,并include proxy.conf文件:

[root@localhost?conf]#?cat?nginx.confserver?{listen???????80;server_name??localhost;#charset?koi8-r;#access_log??logs/host.access.log??main;location?/?{root???html;proxy_pass????http://127.0.0.1:7777;include????proxy.conf;index??index.php?index.html?index.htm;}#以下三行好像不用加location?~?.*\.(js|css|jpg|png)$?{proxy_pass?http://127.0.0.1:7777;}****************

備注:如果只加proxy_pass一行信息,可能會造成頁面能訪問,但是css等樣式文件加載不出來,只能顯示文字信息。


proxy.conf配置文件:

[root@localhost?conf]#?cat?proxy.conf #?proxy.conf client_body_buffer_size?????256k; client_body_temp_path???????client_body?1?2; client_max_body_size????????50m; proxy_buffers???????????????4?32k; proxy_buffer_size???????????4k; proxy_busy_buffers_size?????64k; proxy_connect_timeout???????30; proxy_read_timeout??????????60; proxy_redirect??????????????off; proxy_send_timeout??????????30; proxy_set_header????????????Host?$host; proxy_set_header????????????X-Server-Addr?$server_addr; proxy_set_header????????????X-Remote-Addr?$remote_addr; proxy_set_header????????????X-Remote-Port?$remote_port; proxy_set_header????????????X-Forwarded-For?$proxy_add_x_forwarded_for; proxy_set_header????????????X-Forwarded-Port?$server_port; proxy_set_header????????????X-Forwarded-Proto?$scheme; proxy_set_header????????????Server-Type?nginx; proxy_temp_file_write_size??64k; proxy_temp_path?????????????proxy_temp?1?2; proxy_max_temp_file_size????128m; proxy_next_upstream?????????error?timeout?invalid_header?http_500?http_503?http_404;


重啟nginx服務:

[root@localhost?conf]#?systemctl?stop?nginx [root@localhost?conf]#?systemctl?start?nginx


轉載于:https://blog.51cto.com/net881004/2346768

總結

以上是生活随笔為你收集整理的Centos7编译安装nginx并设置反向代理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。