100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > Centos7编译安装nginx并设置反向代理

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

时间:2021-05-06 22:11:44

相关推荐

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

一、编译部署Nginx 1.12

安装配置:

[root@localhost~]#groupaddnginx[root@localhost~]#useradd-s/sbin/nologin-gnginx-Mnginx[root@localhost~]#systemctlstopfirewalld[root@localhost~]#systemctldisablefirewalld#关掉selinux#服务器文件描述符等

[root@localhost~]#yuminstallgccgcc-c++glibcautomakepcrezlipzlib-developenssl-develpcre-develwgetlrzsz[root@localhost~]#cd/usr/local/src/[root@localhostsrc]#wget/download/nginx-1.12.0.tar.gz[root@localhostsrc]#tar-zxvfnginx-1.12.0.tar.gz[root@localhostsrc]#cdnginx-1.12.0[root@localhostnginx-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@localhostnginx-1.12.0]#make[root@localhostnginx-1.12.0]#makeinstall

备注:

--prefix:Nginx安装目录

--user:Nginx用户

--group:Nginx用户所属组

--with-http_ssl_module:提供https支持

--with-http_flv_module:搭建flv视频服务器使用的

--with-http_stub_status_module:开启Stub Status模块,该模块会产生一个服务器状态和信息页

--with-http_gzip_static_module:开启Gzip静态模块,该模块用于发送预压缩文件

--with-pcre:perl执行文件路径

配置服务:

[root@localhostnginx-1.12.0]#vi/usr/lib/systemd/system/nginx.service[Unit]Description=ThenginxHTTPandreverseproxyserverAfter=network.targetremote-fs.targetnss-lookup.target[Service]Type=forkingPIDFile=/usr/local/nginx/logs/nginx.pidExecStartPre=/usr/bin/rm-f/run/nginx.pidExecStartPre=/usr/local/nginx/sbin/nginx-tExecStart=/usr/local/nginx/sbin/nginxExecReload=/bin/kill-sHUP$MAINPIDKillMode=processKillSignal=SIGQUITTimeoutStopSec=5PrivateTmp=true[Install]WantedBy=multi-user.target

验证:

[root@localhostnginx-1.12.0]#chmoda+x/usr/lib/systemd/system/nginx.service[root@localhostnginx-1.12.0]#/usr/local/nginx/sbin/nginx-tnginx:theconfigurationfile/usr/local/nginx/conf/nginx.confsyntaxisoknginx:configurationfile/usr/local/nginx/conf/nginx.conftestissuccessful[root@localhostnginx-1.12.0]#systemctlstartnginx[root@localhostnginx-1.12.0]#ps-ef|grepnginxroot244121016:31?00:00:00nginx:masterprocess/usr/local/nginx/sbin/nginxnginx244132441:31?00:00:00nginx:workerprocessroot2441510541016:31pts/000:00:00grep--color=autonginx

访问:

http://192.168.146.136

二、nginx配置反向代理

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

[root@localhostconf]#catnginx.confserver{listen80;server_namelocalhost;#charsetkoi8-r;#access_loglogs/host.access.logmain;location/{roothtml;proxy_passhttp://127.0.0.1:7777;includeproxy.conf;indexindex.phpindex.htmlindex.htm;}#以下三行好像不用加location~.*\.(js|css|jpg|png)${proxy_passhttp://127.0.0.1:7777;}****************

备注:如果只加proxy_pass一行信息,可能会造成页面能访问,但是css等样式文件加载不出来,只能显示文字信息。

proxy.conf配置文件:

[root@localhostconf]#catproxy.conf#proxy.confclient_body_buffer_size256k;client_body_temp_pathclient_body12;client_max_body_size50m;proxy_buffers432k;proxy_buffer_size4k;proxy_busy_buffers_size64k;proxy_connect_timeout30;proxy_read_timeout60;proxy_redirectoff;proxy_send_timeout30;proxy_set_headerHost$host;proxy_set_headerX-Server-Addr$server_addr;proxy_set_headerX-Remote-Addr$remote_addr;proxy_set_headerX-Remote-Port$remote_port;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;proxy_set_headerX-Forwarded-Port$server_port;proxy_set_headerX-Forwarded-Proto$scheme;proxy_set_headerServer-Typenginx;proxy_temp_file_write_size64k;proxy_temp_pathproxy_temp12;proxy_max_temp_file_size128m;proxy_next_upstreamerrortimeoutinvalid_headerhttp_500http_503http_404;

重启nginx服务:

[root@localhostconf]#systemctlstopnginx[root@localhostconf]#systemctlstartnginx

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。