nginx不同端口映射到80端口,http和https同时请求

重点

location / {
    proxy_pass http://localhost:8090;
    proxy_redirect default ;
}
location /xcx/{
   proxy_pass http://localhost:8091/;    
   proxy_redirect default;
} 

如果想通过 http://localhost:/xcx/a.html访问 http://localhost:8091/
则 proxy_pass http://localhost:8091/;
最后一定要加反斜杠,要不然会报404;

想访问http同时访问https

listen       80;
listen       443 ssl;
server_name  localhost;
#charset koi8-r;
#access_log  logs/host.access.log  main;
ssl_certificate     certificate.crt;
ssl_certificate_key privatekey.key;

443后面一定要加ssl,不然http会被重定向到https

全部代码如下

#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;


#gzip on; 
server {
listen 80;
listen 443 ssl;
server_name localhost;


#charset koi8-r;


#access_log logs/host.access.log main;
ssl_certificate certificate.crt;
ssl_certificate_key privatekey.key;
location / {
proxy_pass http://localhost:8090;
proxy_redirect default ;
}
location /xcx/{
proxy_pass http://localhost:8091/;
proxy_redirect default;
}   
#error_page 404 /404.html;


# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}


# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}


# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}


# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
nginx可以通过配置文件来实现端口映射。在nginx的配置文件中,可以使用`listen`指令来指定监听的端口号。例如,如果想要将80端口映射到8080端口,可以在配置文件中添加以下内容: ``` server { listen 80; server_name example.com; location / { proxy_pass http://127.0.0.1:8080; } } ``` 在这个配置中,`listen 80;`表示监听80端口,`proxy_pass http://127.0.0.1:8080;`表示将请求转发到本地的8080端口。这样,当访问80端口时,nginx会将请求转发到8080端口上。请注意,`server_name`指令用于指定域名,如果没有域名,可以将其改为`localhost`。\[1\] #### 引用[.reference_title] - *1* [nginx端口映射 nginx反向代理配置](https://blog.csdn.net/qq_41772384/article/details/124251701)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [如何在Nginx中配置端口映射?花生壳和Nginx的配置使用教程](https://blog.csdn.net/oray2013/article/details/123926475)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值