Centos7编译安装nginx并设置反向代理
生活随笔
收集整理的這篇文章主要介紹了
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并设置反向代理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 从0到1开发实战手机站(二):Git提交
- 下一篇: centos7 ssh 密码拒绝_Cen