上一篇:銀河麒麟服務(wù)器v10 sp1 nginx開機自動啟動_csdn_aspnet的博客-CSDN博客
?由于項目為前后端分離,前端項目使用nginx部署,VUE項目打包后上傳至銀河麒麟服務(wù)器:
8063 為前端項目文件目錄,修改配置?,默認配置沒有處理:
?sudo systemctl stop?nginx.service
?sudo systemctl status nginx.service
sudo systemctl start?nginx.service
?
異常信息:Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
開始以為是配置文件的問題,然而在本機測試是可以正常啟動,于是開始查找端口是否占用問題:
?
并沒有占用,還能是什么問題?使用 命令 sudo systemctl status nginx.service 看看能不能鎖定具體問題:
明顯看到80端口被占用了,這才想到開始修改配置的時候默認80端口并沒有處理:
netstat -apn|grep :80
kill 58758 #殺死進程
將配置文件下載到本機,修改后上傳服務(wù)器,配置如下:
#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;
client_max_body_size 50M;
fastcgi_intercept_errors on;
add_header X-Frame-Options SAMEORIGIN;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
#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;
gzip on;
gzip_static on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
server {
listen 8063;
server_name localhost;
location / {
root html/8063;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location ^~ /apis/ {
proxy_pass http://127.0.0.1:8061/;
}
location ^~ /apiz/ {
proxy_pass http://127.0.0.1:8071/;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# 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;
# }
#}
}
執(zhí)行命令:
sudo systemctl stop?nginx.service
?sudo systemctl status nginx.service
sudo systemctl start?nginx.service
使用命令:sudo systemctl status nginx.service 查看具體錯誤:
?nqinx: [emerg] unknown directive "gzip_static"
啟動異常:未知指令,于是將gzip_static on; 注釋 #gzip_static on;,再次執(zhí)行上面命令啟動:
通過上圖看到已經(jīng)啟動成功,在瀏覽器訪問:
?
?難道是靜態(tài)文件沒有訪問權(quán)限,對8063目錄進行授權(quán)操作:
chmod 777 /usr/local/nginx1.25.1/html/8063
再次訪問依然為500,于是開始查找資料:
1. 設(shè)置靜態(tài)網(wǎng)頁或者文件夾權(quán)限
chmod 755 /home/ubuntu/nginxPic/
2. nginx 配置文件,配置server
sudo vi /etc/nginx/nginx.conf
在http里面加sever
server {
listen 92.168.2.380;
server_name 1;
autoindex on; #是否允許訪問目錄
location / {
root html;
index index.html index.htm;
}
在server節(jié)點添加上面紅色部分:
server {
? ? ? ? listen ? ? ? 8063;
? ? ? ? server_name ?localhost;
?? ??? ?autoindex on; #是否允許訪問目錄
? ? ? ? location / {
? ? ? ? ? ? root ? html/8063;
? ? ? ? ? ? index ?index.html index.htm;
? ? ? ? ? ? try_files $uri $uri/ /index.html;
? ? ? ? }
? ? ? ? location ^~ /apis/ {
? ? ? ? ? ? proxy_pass http://127.0.0.1:8061/;
? ? ? ? }
? ? ? ? location ^~ /apiz/ {
? ? ? ? ? ? proxy_pass http://127.0.0.1:8071/;
? ? ? ? }
? ? }
停止,重新啟動nginx,依然沒有解決。查看配置到 root ? html/8063; 這一行的時候,在windows中會自動匹配到nginx下的html的目錄,將此路徑補全,由于代理獲取ip均為127.0.0.1或::1,在server的location節(jié)點下添加請求IP配置,完整配置如下:
#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;
client_max_body_size 50M;
fastcgi_intercept_errors on;
add_header X-Frame-Options SAMEORIGIN;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
#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;
gzip on;
#gzip_static on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
server {
listen 8063;
server_name localhost;
autoindex on; #是否允許訪問目錄
location / {
root /usr/local/nginx-1.25.1/html/8063;
index index.html index.htm;
try_files $uri $uri/ /index.html;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ^~ /apis/ {
proxy_pass http://127.0.0.1:8061/;
}
location ^~ /apiz/ {
proxy_pass http://127.0.0.1:8071/;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# 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;
# }
#}
}
vue項目完整目錄:
root ? /usr/local/nginx-1.25.1/html/8063;
IP配置:
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
配置完成后啟動:
?
?
項目訪問也是成功的,希望對你有幫助。文章來源:http://www.zghlxwxcb.cn/news/detail-605753.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-605753.html
到了這里,關(guān)于銀河麒麟服務(wù)器v10 sp1 nginx 部署項目的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!