当前位置: 首页 > Linux

【搭建后台环境】nginxhttp配置二级域名

时间:2023-04-06 18:20:22 Linux

一、安全规则设置端口在自己购买的云服务平台的控制台中,在云服务器中,选择“安全规则”设置网络访问规则,并将端口设置为子域名端口,不要使用常用端口。2、先启动服务,先启用二级域名服务器,设置端口与安全规则一致。比如开放的3000端口可以直接通过域名访问,http://xxx.com:30003.在nginx安装目录下的conf目录下配置nginxnginx.conf。打开cd/usr/local/nginx/conf编辑vinginx.conf用法一:将当前nginx网站替换成其他网站,内容如下:#usernobody;worker_processes1;#error_loglogs/error.log;#error_loglogs/error.lognotice;#error_loglogs/error.loginfo;#.....omittedserver{listen80;服务器名称本地主机;#charsetkoi8-r;#access_log日志/host.access.logmain;location/{#--------------修改这个----------#roothtml;#索引index.htmlindex.htm;proxy_passhttp://localhost:3000;#Addon}#Omit}第二种情况只是获取二级域名。新的内容如下(注意:新的一定要加在第一个server之后,否则会跑第一个为主站):#usernobody;worker_processes1;#..省略代码http{includemime.类型;default_type应用程序/八位字节流;#log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'#'$status$body_bytes_sent"$http_referer"'#'"$http_user_agent""$http_x_forwarded_for"';#access_log日志/access.logmain;发送文件;#tcp_nopush上;#keepalive_timeout0;keepalive_timeout65;#gzip上;服务器{听80;服务器名称本地主机;#charsetkoi8-r;#access_log日志/host.access.logmain;位置/{根html;indexindex.htmlindex.htm;#proxy_passhttp://localhost:3000;}#..省略代码}#-------------------找到上面server末尾的}括号,添加到下面------server{听80;#端口server_nameapi.xxx.cn;#域名位置/{proxy_passhttp://localhost:3000;#代理地方proxy_http_version1.1;proxy_set_header升级$http_upgrade;proxy_set_header连接“升级”;proxy_set_header主机$host;proxy_cache_bypass$http_upgrade;..省略代码}4.重启nginx,重启加载配置文件/usr/local/nginx/sbin/nginx-sreload记得重启,不要启动/usr/local/nginx/sbin/nginx-sreload访问源码,去掉一些注释,一目了然,在server后面加一条就行了,然后改参数#usernobody;worker_processes1;#error_loglogs/error.log;#error_loglogs/error。日志通知;#error_loglogs/error.loginfo;#pidlogs/nginx.pid;events{worker_connections1024;}http{includemime.types;default_type应用程序/八位字节流;#log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'#'$status$body_bytes_sent"$http_referer"'#'"$http_user_agent""$http_x_forwarded_for"';#access_log日志/access.logmain;发送文件;#tcp_nopush上;#keepalive_timeout0;keepalive_timeout65;#gzip上;服务器{听80;服务器名称本地主机;#charsetkoi8-r;#access_log日志/host.access.logmain;重写^(.*)$https://$host$1永久;#用于将http页面重定向到https页面location/{roothtml;indexindex.htmlindex.htm;}error_page500502503504/50x.html;location=/50x.html{根html;}}#只能在第一个server之后添加,不能在frontserver{listen80;#端口服务器名api.xxx.cn;#域名重写^(.*)$https://$host$1permanent;#用于将http页面重定向到https页面location/{proxy_passhttp://localhost:3000;#proxywhereproxy_http_version1.1;proxy_set_header升级$http_upgrade;proxy_set_header连接“升级”;proxy_set_header主机$host;proxy_cache_bypass$http_upgrade;}}}【原地址】:https://lolku.cn/web/details/posts/38