快捷搜索:

Linux安装nginx,新手快速上手步骤

 

作为一个开发人员,大家应该都用过nginx动态代理吧,话不多说,直接上步骤

注意,在root用户下执行下面步骤:

步骤一:

yum install yum-utils -y

步骤二:

vim /etc/yum.repos.d/nginx.repo

步骤三:

[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key

步骤四:

保存步骤三的内容

步骤五:

yum-config-manager --enable nginx-mainline

步骤六:

yum -y install nginx

至此,nginx安装已经成功

注意点:

注意配置nginx.conf 将 user=root

常用命令:

systemctl start nginx 启动nginx命令 systemctl stop nginx 停止nginx命令 systemctl restart nginx 重启nginx命令

常用配置(80和443端口要在阿里云里面开启)

静态文件:在/etc/nginx/conf.d下建一个web.conf

http方式请求-------- server { listen 80; server_name web.myweb.com; root /usr/local/dict; location / { index index.html index.htm; try_files $uri $uri/ /index.html; } } https方式请求--------------- server { listen 443; server_name web.myweb.com; root /usr/local/dist; location / { index index.html index.htm; try_files $uri $uri/ /index.html; } ssl on; ssl_certificate /usr/cert/web.pem; ssl_certificate_key /usr/cert/web.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; } http自动重定向到https:---------------- server { listen 80; server_name web.myweb.com; return 301 https://web.myweb.com$request_uri; }

代理到后台某一个端口:

listen 80; server_name h5.web.com; location / { proxy_pass http://127.0.0.1:5001/; proxy_redirect default; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } } # 自动跳转到手机页面 server { listen 80; server_name www.myweb.com; location / { proxy_set_header X-Real-IP $remote_addr; proxy_pass http://pc.web.com; if ($http_user_agent ~ "(MIDP)|(WAP)|(UP.Browser)|(Smartphone)|(Obigo)|(Mobile)|(AU.Browser)|(wxd.Mms)|(WxdB.Browser)|(CLDC)|(UP.Link)|(KM.Browser)|(UCWEB)|(SEMC\-Browser)|(Mini)|(Symbian)|(Palm)|(Nokia)|(Panasonic)|(MOT\-)|(SonyEricsson)|(NEC\-)|(Alcatel)|(Ericsson)|(BENQ)|(BenQ)|(Amoisonic)|(Amoi\-)|(Capitel)|(PHILIPS)|(SAMSUNG)|(Lenovo)|(Mitsu)|(Motorola)|(SHARP)|(WAPPER)|(LG\-)|(LG/)|(EG900)|(CECT)|(Compal)|(kejian)|(Bird)|(BIRD)|(G900/V1.0)|(Arima)|(CTL)|(TDG)|(Daxian)|(DAXIAN)|(DBTEL)|(Eastcom)|(EASTCOM)|(PANTECH)|(Dopod)|(Haier)|(HAIER)|(KONKA)|(KEJIAN)|(LENOVO)|(Soutec)|(SOUTEC)|(SAGEM)|(SEC\-)|(SED\-)|(EMOL\-)|(INNO55)|(ZTE)|(iPhone)|(Android)|(Windows CE)|(Wget)|(Java)|(curl)|(Opera)") { proxy_pass http://h5.web.com; } } }

微信认证:wx.conf

server { listen 80; server_name wx.web.com; location ~ ^/[^/]+\.txt$ { return 200 "SCW6Ejcg96n6kqfL"; } }

完毕,至此nginx常用技能掌握完毕!

我是JAVA哥,愿意与大家一些分享java

[注:本文部分图片来自互联网!未经授权,不得转载!每天跟着我们读更多的书]


互推传媒文章转载自第三方或本站原创生产,如需转载,请联系版权方授权,如有内容如侵犯了你的权益,请联系我们进行删除!

如若转载,请注明出处:http://www.hfwlcm.com/info/155906.html