采纳
优质回帖
-
星河鹭起 (Arrogant) • 1 年前
大概给你看下我那个项目的配置,主要看端口里面的文件路径,你要分成两个文件夹,对应的端口访问不同的文件夹就行
server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html/dist; # Add index.php to the list if you are using PHP index index.html index.htm; server_name _; location / { try_files $uri $uri/ @router; index index.html; } location @router{ rewrite ^.*$ /index.html last; } #PROXY-START/pro/ location ^~ /pro/ { #proxy_pass http://44dj498972.qicp.vip/; #proxy_set_header Host 44dj498972.qicp.vip; proxy_pass http://192.0.5.148:8080/; proxy_set_header Host 192.0.5.148:8080; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; add_header X-Cache $upstream_cache_status; #Set Nginx Cache set $static_file7lWCNMk8 0; if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" ) { set $static_file7lWCNMk8 1; expires 12h; } if ( $static_file7lWCNMk8 = 0 ) { add_header Cache-Control no-cache; } } #PROXY-END/pro/ } server { listen 8088; #listen [::]:8088 default_server; root /var/www/html/dist; # Add index.php to the list if you are using PHP index index.html index.htm; server_name _; location / { try_files $uri $uri/ @router; index index.html; } location @router{ rewrite ^.*$ /index.html last; } #PROXY-START/pro/ location ^~ /pro/ { #proxy_pass http://44dj498972.qicp.vip/; #proxy_set_header Host 44dj498972.qicp.vip; proxy_pass http://192.0.5.148:8080/; proxy_set_header Host 192.0.5.148:8080; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; add_header X-Cache $upstream_cache_status; #Set Nginx Cache set $static_file7lWCNMk8 0; if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" ) { set $static_file7lWCNMk8 1; expires 12h; } if ( $static_file7lWCNMk8 = 0 ) { add_header Cache-Control no-cache; } } #PROXY-END/pro/ }
17 回帖
登录参与讨论
...
-
-
-
-
-
光之国肉联厂主任 (eleven) • 1 年前
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } 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; server { listen 8090; server_name localhost 103.239.101.154 www.elevenblog.cn;# 服务器地址或绑定域名 location /Evolve-main { root /usr/local/Evolve-main; # 这里需要看你打包的前端项目放在服务器的那个目录下, 有的教程没有这一步 index index.html ; # 很多教程说需要配置这一步, 自己测试好像不需要 try_files $uri $uri/ /index.html; # 如果没有配置上边root 那一行,你的项目又是在某个目录下, 请加目录不然找不到 栗子: try_files $uri $uri/ /dist/index.html } } #gzip on; # another virtual host using mix of IP-, name-, and port-based configuration # server { listen 80; server_name localhost 103.239.101.154 www.elevenblog.cn;# 服务器地址或绑定域名 #location / { # try_files $uri $uri/ @router;#需要指向下面的@router否则会出现vue的路由在nginx中刷新出现404 # index index.html index.htm; #} #对应上面的@router,主要原因是路由的路径资源并不是一个真实的路径,所以无法找到具体的文件 #因此需要rewrite到index.html中,然后交给路由在处理请求资源 #location @router { # rewrite ^.*$ /index.html last; #} #location /Evolve-main { # root /usr/local/Evolve-main; # 这里需要看你打包的前端项目放在服务器的那个目录下, 有的教程没有这一步 #index /usr/local/Evolve-main/index.html; # 很多教程说需要配置这一步, 自己测试好像不需要 #try_files $uri $uri/ /index.html; # 如果没有配置上边root 那一行,你的项目又是在某个目录下, 请加目录不然找不到 栗子: try_files $uri $uri/ /dist/index.html #} # 配置当不是api开头的请求, 默认全转到静态资源目录, 也就是我们打包完dist目录下的index.html的地址 location / { root /usr/local/nginx/html; # 这里需要看你打包的前端项目放在服务器的那个目录下, 有的教程没有这一步 #index index.html; # 很多教程说需要配置这一步, 自己测试好像不需要 try_files $uri $uri/ /index.html; # 如果没有配置上边root 那一行,你的项目又是在某个目录下, 请加目录不然找不到 栗子: try_files $uri $uri/ /dist/index.html #proxy_pass http://103.239.101.154:8080/personblog/; } location ^~ /api { # ^~/api 表示匹配前缀为api的请求 proxy_pass http://103.239.101.154:8080/personblog/; # 注:proxy_pass的结尾有/, -> 效果:会在请求时将/api/*后面的路径直接拼接到后面 # proxy_set_header作用:设置发送到后端服务器(上面proxy_pass)的请求头值 # 【当Host设置为 $http_host 时,则不改变请求头的值; # 当Host设置为 $proxy_host 时,则会重新设置请求头中的Host信息; # 当为$host变量时,它的值在请求包含Host请求头时为Host字段的值,在请求未携带Host请求头时为虚拟主机的主域名; # 当为$host:$proxy_port时,即携带端口发送 ex: $host:8080 】 #proxy_set_header Host $host; #proxy_set_header X-Real-IP $remote_addr; # 在web服务器端获得用户的真实ip 需配置条件① 【 $remote_addr值 = 用户ip 】 #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;# 在web服务器端获得用户的真实ip 需配置条件② #proxy_set_header REMOTE-HOST $remote_addr; # proxy_set_header X-Forwarded-For $http_x_forwarded_for; # $http_x_forwarded_for变量 = X-Forwarded-For变量 } } # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
0 0 0 -
-
-
-
光之国肉联厂主任 (eleven) • 1 年前
开了8090端口,不知道是不是因为反向代理的问题,我就是不能正常访问。访问,浏览器就找不到静态文件,但是那个静态文件是nm博客的啊
1 回复 0 0 0 -
-
-
星河鹭起 (Arrogant) • 1 年前
大概给你看下我那个项目的配置,主要看端口里面的文件路径,你要分成两个文件夹,对应的端口访问不同的文件夹就行
server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html/dist; # Add index.php to the list if you are using PHP index index.html index.htm; server_name _; location / { try_files $uri $uri/ @router; index index.html; } location @router{ rewrite ^.*$ /index.html last; } #PROXY-START/pro/ location ^~ /pro/ { #proxy_pass http://44dj498972.qicp.vip/; #proxy_set_header Host 44dj498972.qicp.vip; proxy_pass http://192.0.5.148:8080/; proxy_set_header Host 192.0.5.148:8080; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; add_header X-Cache $upstream_cache_status; #Set Nginx Cache set $static_file7lWCNMk8 0; if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" ) { set $static_file7lWCNMk8 1; expires 12h; } if ( $static_file7lWCNMk8 = 0 ) { add_header Cache-Control no-cache; } } #PROXY-END/pro/ } server { listen 8088; #listen [::]:8088 default_server; root /var/www/html/dist; # Add index.php to the list if you are using PHP index index.html index.htm; server_name _; location / { try_files $uri $uri/ @router; index index.html; } location @router{ rewrite ^.*$ /index.html last; } #PROXY-START/pro/ location ^~ /pro/ { #proxy_pass http://44dj498972.qicp.vip/; #proxy_set_header Host 44dj498972.qicp.vip; proxy_pass http://192.0.5.148:8080/; proxy_set_header Host 192.0.5.148:8080; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; add_header X-Cache $upstream_cache_status; #Set Nginx Cache set $static_file7lWCNMk8 0; if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" ) { set $static_file7lWCNMk8 1; expires 12h; } if ( $static_file7lWCNMk8 = 0 ) { add_header Cache-Control no-cache; } } #PROXY-END/pro/ }
1 回复 0 1 0 -
-
-
-
-
大概给你看下我那个项目的配置,主要看端口里面的文件路径,你要分成两个文件夹,对应的端口访问不同的文件夹就行