Nginx相关问题
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Nginx相关问题,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1708字,纯文字阅读大概需要3分钟。
内容图文
1、前端页面刷新,404问题。
vue单页因微信分享和自动登录需要,对于URL中存在’#’的地址,处理起来比较坑。用history模式就不会存在这样的问题。但是换成history模式,就会有个新的问题,就是页面刷新后,页面就无法显示了(404)。对于这个问题,我们只需要在服务器配置如果URL匹配不到任何静态资源,就跳转到默认的index.html。
server {
listen 8888;
server_name localhost;
root E:/vue/my_project/dist;
location / {
try_files $uri $uri/ @router;
index index.html index.htm;
}
location @router {
rewrite ^.*$ /index.html last;
}
}
2、解析远程真实IP的相关问题:
server {
listen 8888;
server_name localhost;
root E:/vue/my_project/dist;
location / {
index index.html index.htm;
proxy_set_header X-Real-IP $remote_addr;
}
}
3、Windows下nginx相关操作:
#启动
start nginx
#停止
nginx -s stop
#重启
nginx -s reload
4、Linux下ningx相关操作:
#首先利用配置文件启动Nginx:
nginx -c /usr/local/nginx/conf/nginx.conf
重启服务:
service nginx restart
#快速停止或关闭Nginx:
nginx -s stop
#正常停止或关闭Nginx:
nginx -s quit
# 配置文件修改重装载命令:
nginx -s reload
5、完整配置案例
http {
include mime.types;
default_type application/octet-stream;
#log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
# ‘$status $body_bytes_sent "$http_referer" ‘
# ‘"$http_user_agent" "$http_x_forwarded_for"‘;
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream fabric {
server 192.168.1.118:8085;
}
server {
listen 9527;
server_name 192.168.1.118;
client_max_body_size 1000M;
root D:/software/nginx-1.14.0/dist;
location / {
try_files $uri $uri/ @router;
index index.html index.htm;
proxy_set_header X-Real-IP $remote_addr;
}
location @router {
rewrite ^.*$ /index.html last;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
原文:https://www.cnblogs.com/jockming/p/12170571.html
内容总结
以上是互联网集市为您收集整理的Nginx相关问题全部内容,希望文章能够帮你解决Nginx相关问题所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】